0
如何將用戶獲得的分數從最高分到最低分三次進行測試?另外,如何按照字母順序對用戶名進行排序,並在代碼運行時將他們的分數與他們的姓名相鄰?如何對測驗完成3次時獲得的分數進行排序?
school_data = []
for x in range (0,3):
quiz = dict()
print ("Enter your name")
quiz['name'] = input()
print ("what class")
quiz['class_code'] = input()
print("1. 9+10=")
answer = input()
answer = int(answer)
if answer == 19:
print("correct")
score = score + 1
else:
print("wrong")
print("2. 16+40=")
answer = input()
answer = int(answer)
if answer == 56:
print("correct")
score = score + 1
else:
print("wrong")
print("3. 5+21=")
answer = input()
answer = int(answer)
if answer == 26:
print("correct")
score = score + 1
else:
print("wrong")
print("4. 5-6=")
answer = input()
answer = int(answer)
if answer == -1:
print("correct")
score = score + 1
else:
print("wrong")
print("5. 21-9=")
answer = input()
answer = int(answer)
if answer == 12:
print("correct")
score = score + 1
else:
print("wrong")
quiz['score'] = score
school_data.append(quiz)
W你有沒有試過的帽子?您存儲測驗結果,分數和用戶的數據結構是什麼?測驗本身的代碼與這個問題並不特別相關。 –