Python入門學習札記
學習課程:風變編程 - Python入門
https://www.pypypy.cn/
1、輸入數組,判斷結果
print('輸入學生的成績,每個成績以,鍵隔開\n')
arr = input("")
print('\n')
HistoryScore = [int(n) for n in arr.split(',')]
#將輸入每個數以,鍵隔開做成數組
HistoryScore_length = len(HistoryScore)
print('總計有',HistoryScore_length,'個學生\n')
print('學生的成績是:',HistoryScore,'\n')
count = 0
while (count < HistoryScore_length):
if HistoryScore[count] >= 60:
print('第',str(count+1),'個同學',HistoryScore[count],'分: 你已經及格')
if HistoryScore[count] >= 80:
print('評語:你很優秀')
else:
print('評語:你只是一般般')
else:
print('第',str(count+1),'個同學',HistoryScore[count],'分: 你不及格')
if HistoryScore[count] < 30:
print('評語:學渣')
else:
print('評語:還能搶救一下')
print('程序結束\n')
count = count + 1
輸入:90,70,50,20
2、多層if-elif-else語句嵌套
Salary = int(input("請輸入工資數:"))
print('\n')
if Salary <= 500:
print('“歡迎進入史塔克窮人幫前三名”')
if 100 < Salary <=500:
print('“請找弗瑞隊長加薪”','\n','程序結束')
else:
print('“恭喜您榮獲“美元隊長”稱號!”','\n','程序結束')
elif 500< Salary <=1000:
print('“祝賀您至少可以溫飽了。”','\n','程序結束')
else Salary > 1000:
print('“經濟危機都難不倒您!”')
if 1000 < Salary <=20000:
print('“您快比鋼鐵俠有錢了!”','\n','程序結束')
else:
print('“您是不是來自於瓦坎達國?”','\n','程序結束')
輸入:20000
###3、輸入輸出,浮點運算的小數位
print('您好,歡迎來到古靈閣,請問您需要幫助嗎?\n請輸入數字:')
str = input('1 需要;2 不需要\n')
num = int(str)
if num == 1:
print('請問您需要什麼幫助呢?\n請輸入數字:')
str = input('1 存取款;2 貨幣兌換;3 諮詢 \n')
else:
print('好的,再見。')
task = int(str)
if task == 1:
print('請去存取款窗口\n程序結束')
elif task == 3:
print('請去諮詢窗口\n程序結束')
elif task == 2:
print('金加隆和人民幣的兌換率爲1:51.3,即一金加隆=51.3人民幣')
str = input('請問您需要兌換多少金加隆呢?\n')
money = float(str)
cal = format(money*51.3, '.2f')
#將產生一個浮點數作爲一個四捨五入爲兩個小數點的字符串
print('那麼,您需要付給我',cal,'人民幣。\n程序結束')
else:
print('不在服務範圍,程序結束')