# Python
:::success
### Table of Contents
[TOC]
:::
### Links
[meet](https://meet.google.com/njo-gfyh-dwj)
[online compiler](https://www.programiz.com/python-programming/online-compiler/)
[Python 3.10.7 Download](https://www.python.org/ftp/python/3.10.7/python-3.10.7-amd64.exe)
[VSCode Download](https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user)
[Fast Finger](https://10fastfingers.com/typing-test/english)
### language
VHDL

verilog


### sort and search
```bubble sort & bin-search```
```python=
# global
val={}
# sort func_
def sort():
for x in range(int(len(val))-1):
for y in range(x+1,int(len(val))):
# print(y)
if val[x]>val[y]:
tmp=val[x]
val[x]=val[y]
val[y]=tmp
print(val)
#search func_
def search(g, l, r):
mid=int((l+r)/2)
if l>r:
print('err0r')
return
elif val[mid] is g:
print(f'index:{mid}')
return
elif val[mid]<g:
search(g, mid+1, r)
else:
search(g, l, mid-1)
# main
n=int(input('input how many numbers in the array?\n> '))
print('input')
for i in range(n):
val[i]=int(input(f'{i+1}. '))
sort()
m=int(input('input how many numbers need to search?\n> '))
print('input')
for i in range(m):
tmp=int(input(f'{m}. '))
search(tmp, 0, int(len(val))-1)
```
### 1110921
- hw1:
```python=
name=str(input('Hello sir, Please input ur name\n> '))
print(f'Hello, {name}. Welcome back!')
```
- monument

### 1110928
- Python 變數概念
> 概念:類似C++ `auto` 型態
>
> 命名法則:同C++
```python=
a=int(input('Input the first number.\n> '))
b=int(input('Input the first number.\n> '))
print(f'{a} + {b} = {a + b}')
print(f'{a} - {b} = {a - b}')
print(f'{a} * {b} = {a * b}')
print(f'{a} / {b} = {a / b}')
print(f'{a} % {b} = {a % b}')
```
- operator概念
- arithmetic operator
> \+ : 加法
> \- : 減法
> \* : 乘法
> \/ : 除法
> \% : 模除
### 1111012
- 四捨五入
- module: `round`
```python=
print(round(2/3))
```
- 實作:`temperature convert`
```python=
temperature= input(('Input the temperature (included °C or °F or K)\n> '))
temperature= temperature.split(' ')
temperature[1]= temperature[1].lower()
# print(temperature)
if temperature[1] == '°c':
# print('C')
temperature.insert(2, round(int(temperature[0])))
elif temperature[1] == '°k':
# print('F')
temperature.insert(2, round((int(temperature[0])-32)*5/9))
elif temperature[1] == 'k':
# print('K')
temperature.insert(2, round(int(temperature[0])-273.15))
else:
print('3rr0r')
temperature.insert(3, round(temperature[2]*9/5+32))
temperature.insert(4, round(temperature[2]+273.15))
print(temperature)
```
- compare operator
```python=
a= int(input('Input value of a:\n> '))
b= int(input('Input value of b:\n> '))
print(f'a == b is {a == b}')
print(f'a != b is {a != b}')
print(f'a >= b is {a >= b}')
print(f'a > b is {a > b}')
print(f'a <= b is {a <= b}')
print(f'a < b is {a < b}')
```
### 111019
- 優先度概念
- 算數運算子 (arithmetic operator) > 比較運算子(comparison operator) > 邏輯運算子(logical operator)
- [參考文章](https://magicjackting.pixnet.net/blog/post/70902861)
```python=
print(1/2 > 1 and 1 != 1)
print(True or False or True)
print(1 < 1 and 5 == 6 or 7 > 7)
```
> result:
>
> \> False
>
> \> True
>
> \> False
### 1111102
```python=
num=int(input('Input a number\n> '))
if not num%3:
print(f'{num} is 3\'s mutiple')
else:
print(f'{num} isn\'t 3\'s mutiple')
```
### 1111109
```python=
score=int(input('Input your score'))
if 100>=score>=90:
print('優等')
elif 90>score>=80:
print('甲等')
elif 80>score>=70:
print('乙等')
elif 70>score>=60:
print('丙等')
elif 60>score>=0:
print('丁等')
else:
print('err0r')
```
### 1111116
```python=
dish_lst=('1.陽春麵', '2.鍋燒意麵', '3.滷肉飯', '4.水')
price_lst=(70, 80, 90, 100)
def inp():
global ordr
ordr=int(input(f'Welcome to Lin\'s Kitchen Here is the menu\n{dish_lst}\nPlease input the index of your order\n> '))
def main():
inp()
try:
print(f'Your order cost {price_lst[ordr-1]} dollars.')
except:
print(f'err0r')
main()
main()
```
### 1111123
```python=
for i in range(1,11):
print(f'No.{i}')
```
```python=
start = 1
lim = 10000
print(f'The result between {start} to {lim}\n> ')
lis=[]
for i in range(1,lim+1):
if i % 3 == 2 and i % 5 == 3 and i % 7 != 5:
lis.append(i)
for i in lis:
print(i, end ='')
if i != lis[len(lis)-2]:
print(', ', end = '')
print()
```
### 1111130
##### isPrime
```python=
import math
inp = int(input('Is this prime?'))
isPrime=True
for i in range(2, int(math.sqrt(inp))+1):
if inp % i == 0:
isPrime=False
break
print(f'{inp} == prime is {isPrime}')
```
##### isBeautiful
```python=
import math
num = int(input('Is this number beautiful?\n> '))
total = 1
for x in range(2, int(math.sqrt(num))+2):
if not num % x:
total *= x
if total == num:
print(f'{num} is beautiful.')
else:
print(f'{num} is ugly.')
```