# 程式設計(第24組) 14/02/2022
組長:黃凱葶 110251039 管院學士班學士班1年級
組員:林世鎧 110211052 經濟系學士班1年級
組員:周芃君 110211008 經濟系學士班1年級
組員:蘇家陞 110211033 經濟系學士班1年級
---
## `基本概念`
>print() :加了挂號成爲函數
>():挂號帶進去的叫參數
>x=9:=是指定的意思
>x=9:把9指定給x的變數
>ctrl + m + b (+程式碼的快捷鍵)
---
## `基礎練習`
#### `Python Arithmetic Operators`
| Operator | Name | Example |
| -------- | ------------- | ------- |
| + | Addition(加) | x + y |
| - | Subtraction(減) | x - y |
| * | Multiplication(乘) | x * y |
| / | Division(除) | x / y |
| % | Modulus(餘數) | x % y |
| ** | Exponentiation(模冪)| x ** y |
| // | Floor division(商數)| x //y |
1.x+y
x=2
y=3
print(x+y)
5
2.x-y
x=3
y=2
print(x-y)
1
3.x*y
x=1
y=2
print(x*y)
2
4.x/y
x=4
y=2
print(x/y)
2
5.x%y(% Modulus餘數)
x=5
y=2
print(x%y)
1
5.x**y(**Exponentiation模冪)
x=2
y=5
print(x**y)
32
6.x//y(//Floor division商數)
x=5
y=2
print(x//y)
2
---
#### `Python Assignment Operators`
| Operator | Example | Same as |
| -------- | ------- | ------- |
| = | x = 5 | x = 5 |
| += | x += 3 | x = x + 3 |
| -= | x -= 3 | x = x - 3 |
| * = | x -= 3 | x = x * 3 |
| /= | x /= 3 | x = x / 3 |
| %= | x %= 3 | x = x % 3 |
| **= | x **= 3 | x = x ** 3|
| //= | x //= 3 | x = x // 3|
| &= | x &= 3 | x = x & 3 |
| ^= | x ^= 3 | x = x ^ 3 |
| >>= | x >>= 3 | x = x >> 3|
| <<= | x <<= 3 | x = x << 3|
1.x=5
print(x)
5
2.x=5
x=x+3
print(x)
8
3.x=5
x=x-3
print(x)
2
4.x=5
x=x*3
print(x)
15
5.x=5
x=x/3
print(x)
1.6666666666666667
6.x=5
x=x%3
print(x)
2
7.x=5
x=x//3
print(x)
1
8.x=5
x=x**3
print(x)
125
9.x=5
x=x*3
print(x)
15
---
#### `Python Comparison Operators`
| Operator | Column 2 | Column 3 |
| -------- | ----------------------- | -------- |
| == | Equal | x == y |
| != | Not equal | x != y |
| > | Greater than | x > y |
| < | Less than | x < y |
| >= | Greater than or equal to| x >= y |
| <= | Less than or equal to | x <= y |
1.= =(Equal)
x=5
y=3
print(x==y)
False
2.!=(Not Equal)
x=5
y=3
print(x!=y)
True
3.>(Greater Than)
x=5
y=3
print(x>y)
True
4.<(Less Than)
x=5
y=3
print(x<y)
False
5.>=(Greater than or equal to)
x=5
y=3
print(x>=y)
True
6.<=(Less than or equal to)
x=5
y=3
print(x<=y)
False
---
#### `Python Logical Operators`
| Operator| Description| Example|
| -------- | -------- | -------- |
| and | Returns True if both statements are true| x < 5 and x < 10 |
| or | Returns True if one of the statements is true | x < 5 or x < 4 |
| not | Reverse the result, returns False if the result is true | not(x < 5 and x < 10) |
1.and(Returns True if both statements are true如果兩個是算式是 對的,那就是true)
x=5
print(x>3 and x<10)
True
2.or(Returns True if one of the statements is true如果其中一 個算是是對的,那就是true)
x=5
print(x>3 or x<10)
True
- [ ] 原因:returns True because one of the conditions are true (5 is greater than 3, but 5 is not less than 4)
3.not(Reverse the result, returns False if the result is true)
x=5
print(not(x>3 and x<10))
False
- [ ] 原因:returns False because not is used to reverse the result