2017-08-10 53 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