我試圖創建一個程序來詢問用戶的用戶名和密碼。如果登錄詳細信息是正確的,程序應詢問學生姓名,然後要求三個分數,每個主題一個分數。該計劃應詢問用戶是否希望輸入其他學生的詳細信息。該計劃應輸出每個主題的平均分數。我無法弄清楚如何爲每個學生輸入每個主題的學生分數,以及如何計算每個主題的平均分數。三個主題的標記平均值
你能幫忙嗎?
login="teacher"
password="school"
usrnm=input("Please enter your username: ")
pw=input("Please enter your password: ")
if (usrnm==login) and (pw==password):
print("==Welcome to the Mathematics Score Entry Program==")
print("Do you want to enter the students score? Yes/No: ")
option = input()
option = option.title()
student_info = {}
student_data = ['Topic 1 : ', 'Topic 2 : ', 'Topic 3 : ']
while (option != "No"):
student_name = input("Name: ")
student_info[student_name] = {}
score1 = int(input("Please enter the score for topic 1: "))
student_info[student_name][Topic_1] = score1
score2 = int(input("Please enter the score for topic 2: "))
student_info[student_name][Topic_2] = score2
score3 = int(input("Please enter the score for topic 3: "))
student_info[student_name][Topic_3] = score3
print("Do you want to enter the students score? Yes/No: ")
option = input()
option = option.title()
average = sum(student_info.values())/len(student_info)
average = round(average,2)
print ("The average score is ", average)
else:
print("Access denied!")
你需要跟蹤的主題的平均成績,或每個學生的分數? – AllenMoh
輸出每個主題的平均分數(三個主題)。 – MrFHHH
topic_one_scores = [學生信息中學生的分數[0]] average_topic_one =總和(topic_one_scores)/ len(topic_one_scores)這不起作用。 – MrFHHH