2017-08-10 87 views
-1

我試圖創建一個程序來詢問用戶的用戶名和密碼。如果登錄詳細信息是正確的,程序應詢問學生姓名,然後要求三個分數,每個主題一個分數。該計劃應詢問用戶是否希望輸入其他學生的詳細信息。該計劃應輸出每個主題的平均分數。我無法弄清楚如何爲每個學生輸入每個主題的學生分數,以及如何計算每個主題的平均分數。三個主題的標記平均值

你能幫忙嗎?

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!") 
+0

你需要跟蹤的主題的平均成績,或每個學生的分數? – AllenMoh

+0

輸出每個主題的平均分數(三個主題)。 – MrFHHH

+0

topic_one_scores = [學生信息中學生的分數[0]] average_topic_one =總和(topic_one_scores)/ len(topic_one_scores)這不起作用。 – MrFHHH

回答

1

只保留標記從學生的姓名

students = [] 
marks = [] 
option = "" 
while (option != "No"): 
    students.append(input("Name")) 
    marks.append([float(input("Mark_Category1:")), 
        float(input("Mark_Category2:")), 
        float(input("Mark_Category3:"))]) 
    option = input("Add Another?") 

import numpy 
print(numpy.average(marks,0)) 

獨立的,如果你真的想這樣做沒有numpy的

averages = [sum(a)/float(len(a)) for a in zip(*marks)] # transpose our marks and average each column 
+0

什麼是numpy,因爲我以前從未見過。 – MrFHHH

+0

numpy是一個廣泛使用的數學庫...你可以做到這一點沒有numpy很容易,但它更容易使用numpy –

+0

感謝您向我介紹這一點,但你能告訴我如何做到這一點沒有numpy? – MrFHHH