Python 

整合開發環境(IDE)









變數與資料型態









 


資料型態轉換


for loop:

for variable in range (start, stop, step):

#start 是序列的起始值,stop 是序列結束值(但不包括在內),step 是步長(遞增或遞減的量)

Range


 













購物清單

 shopping_list = ["蘋果", "香蕉", "麵包"]

for item in shopping_list:

    print(item)




倒數計時

 for count_down in range(5, 0, -1):

    print(count_down)

print("起飛!")



倒數日期 

 from datetime import datetime

# 假設你的生日是 9 月 10 日

birthday = datetime(datetime.now().year, 9, 10)

current_date = datetime.now()

difference = birthday - current_date

print("距離你的生日還有", difference.days, "天")

# 要加絕對值 abs()


Colab

 先要載入套件

!pip3 install ColabTurtle






 滙入元件

from ColabTurtle.Turtle import *

 

初始化 (清螢幕)

initializeTurtle()



畫正方形 (請改成For Loop)


speed(3)

forward (100)

right (90)

forward (100)

right (90)

forward (100)

right (90)

forward (100)



Turtle online  test 

基本題


進階

畫出一個實心的直角三角形


加分


 

#資料型態錯誤 

#input()所接收的資料型態是字串(string))

scoreA = input("請輸入國文成績:")

scoreB = input("請輸入英文成績:")

scoreC = input("請輸入數學成績:")

total = screA + scoreB + screC

print(ttal)

print("你的總分數是:" + total)

=========================

提示:使用 int(), str()進行資料型態轉換

 

 

=========================

【實作練習:求平均跟總和】

讓使用者輸入任意兩個數字,能夠輸出總和(sum)及平均(average)


=========================

【實作練習:小費計算公式】


九上_第二章-Python_2-計算_N.pptx