國一資訊科技

平均數計算

#線上練習寫python程式 https://repl.it/languages/python3
也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

a = int(input('請輸入a='))

b = int(input('請輸入b='))

c = (a+b)/2

print('平均數為 ' , c)

學期成績計算

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

a = int(input('輸入作業成績 = '))

b = int(input('輸入測驗成績 = '))

c = int(input('輸入平時表現成績 = '))

grades = a*0.4 + b*0.4 + c*0.2

print('學期成績 = ' , grades)

if grades < 60 :

print('不及格')

else:

print('及格')

累加運算變數值表

N 數字 和0 1 01 2 12 3 33 4 64 5 105 6 156 7 217 8 288 9 369 10 4510 11 55

累加運算

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

N = int(input('請輸入數字N '))

sum = 0

a = 1

for a in range(1,N+1,1):

sum = sum + a

a = a + 1

print('1+2+...+N = ',sum)

累積運算變數值表

N 數字 積0 1 11 2 12 3 23 4 64 5 245 6 1206 7 7207 8 50408 9 40320 9 10 36288010 11 3628800

累積計算

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

N = int(input('請輸入數字N '))

product = 1

a = 1

for a in range(1,N+1,1):

product = product * a

a = a + 1

print('1*2*...*N = ',product)

密碼驗證

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

password = 137 #密碼

n = 1 #次數

a = int(input('請輸入密碼'))

while a != password and n!=3:

print('密碼錯誤第',n,'次')

n=n+1

a = int(input('請輸入密碼'))

if a==password:

print('歡迎使用本系統')

else:

print('密碼輸入錯誤3次,帳號已被鎖定')

99乘法表

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

for i in range(1,10,1):

for j in range(1,10,1):

print('%3d' %(i*j),end='')

print()

溫度轉換

#線上練習寫python程式 https://repl.it/languages/python3

#Python程式碼如下:

val = input("請輸入溫度,例如:32C ")

if val[-1] in ["C","c"]:

f = 1.8 * float(val[0:-1]) + 32

print("轉換後的溫度為: %.2f F"%f)

elif val[-1] in ["F","f"]:

c = (float(val[0:-1]) - 32)/1.8

print("轉換後的溫度為: %.2f C"%c)

else:

print("輸入溫度格式有誤")


字元加密(前移7碼)

#線上練習寫python程式 https://repl.it/languages/python3

也可以使用Python Tutor練習及研究程式數值變化

#Python程式碼如下:

def Calc(sInput):

iCnt = 0

sOutput=""

while(iCnt<len(sInput)):

sOutput += chr(ord(sInput[iCnt:iCnt+1:1])-7)

iCnt +=1

sOutput += "\n"

return(sOutput)

#h字母會改輸出a

print(Calc('h'))

畫璇轉正方形

Python教學 | 初學者好用python工具 https://thonny.org/

turtle 龜圖學(繪圖工具) https://docs.python.org/zh-tw/3/library/turtle.html

請使用Thonny Python IDE工具練習用turtle繪圖

from turtle import *

color('blue')

pendown()

for i in range(0,12):

for j in range(0,4):

forward(100)

right(90)

right(30)

penup()

畫擴散方形

Python教學 | 初學者好用python工具 https://thonny.org/

turtle 龜圖學(繪圖工具) https://docs.python.org/zh-tw/3/library/turtle.html

請使用Thonny Python IDE工具練習用turtle繪圖

from turtle import *

color('blue')

pendown()

s=0

for i in range(0,20):

s = s + 10

forward(s)

right(90)

penup()

試算表成績單製作

LiberOffice 自由的辦公軟體

請同學運用試算表(Calc)設計一個班級[成績表]

(1)計算每科最高、最低、平均、及格人數、不及格人數

(2)計算個人總分、平均、班級排名

函數說明:加總:sum(範圍),平均:average(範圍),最大值:max(範圍),最小值:min(範圍),條件計算countif(範圍,條件),排序:rank(值,資料,類型)

rank($H$2:$H$23,0) 在H2:H23固定範圍內排名,由大至小

countif(C2:C23,">=60") 在C2:C23範圍計數>=60的次數