三个主题的平均分数

时间:2017-08-10 17:03:08

标签: python dictionary average

我正在尝试创建一个程序,要求用户输入用户名和密码。如果登录详细信息正确,程序应询问学生姓名,然后要求三个分数,每个主题一个。该程序应询问用户是否希望输入其他学生的详细信息。该计划应输出每个主题的平均分数。我无法弄清楚如何为每个学生输入每个主题的学生成绩,以及如何计算每个课程的平均成绩。

你能帮忙吗?

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

1 个答案:

答案 0 :(得分: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