# Python超超超入門
> Fan Kang Ting
----
哈哈想必各位,升大一的暑假很無聊,既不能出門(疫情影響),也不能好好玩,只能在家摳.....丁
----
# 好
----
### 以上言論不代表本人立場
總之今天來個輕鬆的
----
### 你有學過Python嗎?(我印象很多人有自學)
學過Python 幫我舉右手
學過JavaScript 舉左手(關JS屁事)
---
# Python 3安裝
----
[網站](https://www.python.org/)
----
### 記得安裝時要加入PATH(環境變數)
不然...很痛苦
小建議install for ALL User
---
### VScode 延伸模組
----
### 看到推薦安裝的星星

### 請建立一個python file main.py
然後邊做邊學
---
### 基本語法
----
##### 變數
```python=
a="123"#str
b=123#int
c=123.456#float
d=True #bool
```
對就是這麼的簡單,那是因為Python是動態強型別的語言,你把甚麼丟給變數,變數就是甚麼~~~
----
##### 查看變數型態的方法
```python=
type(a)#str
type(b)#int
type(c)#float
type(d)#bool
```
----
### 容器型別
1. list []
2. tuple ()
3. dictionary {}
4. set {}
----
### list
```python=
list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
type(list1)
<class 'list'>
```
----
### tuple
```python=
tuple1 = ("apple", "banana", "cherry")
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
```
----
### dictionary
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"]) #Ford
```
----
##### Basic I/O
```python=
ans=input("請輸入您的答案")#注意輸入的型態是字串 EX:helloworld
#input() 括弧裡的東西 是輸入時的提示文字
print(ans)#印出helloworld
```
----
###### print補充
print的輸出方式有很多種 同時可以用逗點來輸出不同型別的參數
```python=
print("范綱庭生日: ",910207,"身高:",171.4)
```
那還有f-string format output等等等
也有print()裡面可以修改的參數 例如sep end
[字串格式化文章](https://blog.louie.lu/2017/08/08/outdate-python-string-format-and-fstring/)
----
##### range()
產生序列list
```python=
range(n)#建立一個迭代物件 內容是[0,1,2,3....,n-1]
range(n,m)#內容是[n,n+1,n+2....,m-1]
range(n,m,2)#內容是[n,n+2,n+4....,m-1]
```
----
##### Loop
```python=
for variable in range(9):#in 後面要接迭代物件 比如List tuple dictionary
print(variable) #0 1 2 3 4 5 6 7 8
variable = 8
while variable >0:#while 接 condition
print(variable)# 8 7 6 5 4 3 2 1
variable-=1
```
----
##### if elif else
```python=
if variale==0:
print("variable == 0")
elif variable ==1:
print("variable == 1")
else:
print("variable not 1 or 0")
```
----
### 都學會了嗎 要加入函式搂
----
##### define function
```python=
def 函式名稱(參數名稱1,參數名稱2):
return 參數名稱1+參數名稱2
函式名稱(123,456)#579
```
----
##### 強制轉換型別
```python=
int("123")#123
str(123)#"123"
float(123)#123.0
```
---
### 實作環節
創建一個小程式 功能是 使用者輸入N位同學的姓名後再輸入三個科目成績 分別是 國文,英文,數學成績(使用函數)
創建一個function
每科>=60才能拿到畢業證書
有一顆<60 直接21
其中一科 拿90以上 得到獎學金不累計(只判斷有沒有而已)
----
### Input Example
```code=txt
2 //同學有N位
張三
90
80
70
李四
50
40
70
```
----
### Output Example
```code=txt
張三:獲得畢業證書
張三:有獎學金
李四:21
```
---
### 還是太簡單?
[額外題目](https://www.w3schools.com/python/exercise.asp)
{"metaMigratedAt":"2023-06-16T11:19:53.709Z","metaMigratedFrom":"YAML","title":"Python超超超入門","breaks":true,"contributors":"[{\"id\":\"4c8f8799-9dcd-430b-b7bc-8a5156d39d0b\",\"add\":2736,\"del\":40}]"}