## 參考資源: ### 迴圈 Loop - 天下創新學院-Python程式設計輕鬆學-第13講 - [迴圈幫我們一次解決重複的事](https://medium.com/ccclub/ccclub-python-for-beginners-tutorial-4990a5757aa6) - [搞懂5個Python迴圈常見用](https://www.learncodewithmike.com/2019/12/python.html) ### 函式 Fuction - 天下創新學院-Python程式設計輕鬆學-第16講 - [利用函式處理單一的特定功能](https://medium.com/ccclub/ccclub-python-for-beginners-tutorial-244862d98c18) - [5個必知的Python Function觀念整理](https://www.learncodewithmike.com/2019/12/python-function.html) ### 今日筆記 1. 九九乘法表 - for loop ``` for i in range(2, 10): for j in range(1, 10): print(f'{i} * {j} = {i*j}') print('\n') ``` - while loop ``` i = 2 while i <= 9: j = 1 while j <=9: print(f'{i} * {j} = {i*j}') j = j + 1 i = i + 1 ``` 2. 七九乘法表 - for loop + break ``` for i in range(2, 10): for j in range(1, 10): print(f'{i} * {j} = {i*j}') print('\n') if i == 7: break ``` - while loop + break ``` i = 2 while i <= 9: j = 1 while j <=9: print(f'{i} * {j} = {i*j}') j = j + 1 if i == 7: break i = i + 1 ``` 3. BMI計算器 - 單一計算 ``` def bmi_calculator_1(weight, height): """ BMI = 體重/身高**2 weight: int, 體重(以公斤計) height: float, 身高(以公尺計) """ bmi_value = weight / height**2 return bmi_value ``` - 串列計算 ``` def bmi_cal_list(w_list, h_list): bmi_output=[] for w, h in zip(w_list, h_list): bmi = round((w/(h/100)**2), 2) bmi_output.append(bmi) return bmi_output ```