張佳伃的學習歷程檔案 - 大數據學習之旅 - 9、成績排名 |
|
|
9、成績排名#張佳伃1081a7037 import random import string list_index=["名次","學號","姓名","語文","數學","英語","總分","均分"] #定義字段名 list_name=["小明","小美","阿橋","美美","玲玲","汪汪","阿明","弟弟","小橋","蘇菲"] #定義名字 list_num=[] dict_num={} for i in range(0,len(list_name)): T=[] for j in range(0,3): T.append(random.randint(50,100)) T.append(sum(T)) T.append(T[-1]/len(T)) T.insert(0,list_name[i]) T.insert(0,2000+i) list_num.append(list(T)) T.clear() list_num=sorted(list_num,key=(lambda x:x[6])) list_num.reverse() for i in range(0,len(list_name)): dict_num[str(i+1)]=list_num[i] print("成績統計表".center(54,"#")) print(str(list_index[0]).center(6),end=" ") for j in range(1,8): #循環輸出所有字段名 print(list_index[j].center(5),end=" ") print() print("="*57) for i,j in dict_num.items(): print(str(i).center(8),end=" ") for x in j: print(str(x).center(6),end=" ") print() print("="*57) 實作連結:https://colab.research.google.com/drive/1pGTRci8Z5m4cFtjAKNmTCOoP6jhNlUS4?usp=share_link
|
|