(Python第三天)實例
阿新 • • 發佈:2019-01-17
print 實例 int clas name number fail format 所有
一、判斷學生成績是否達標的程序
1 n = int(input("Enter the number of students:"))#輸入學生數目 2 data = {} #用來存儲數據的字典變量 3 Subjects = (‘Physics‘,‘Maths‘,‘History‘) #元組,定義所有科目 4 for i in range(0,n): 5 name = input(‘Enter the name of the student {}:‘.format(i + 1))#獲得學生名稱 6 marks = [] 7 for x in Subjects:8 marks.append(int(input(‘Enter marks of {}:‘.format(x))))#獲得分數 9 data[name] = marks#把分數存儲到data中 10 for x,y in data.items(): 11 total = sum(y) 12 print("{}‘s total marks {}".format(x,total)) 13 if total < 120: 14 print(x,"failes :(") 15 else: 16 print(x, "passed :)")
(Python第三天)實例