小编MrF*_*HHH的帖子

Python 字典中的平均值

我试图找到全班数学平均分,但我不知道如何在字典中做到这一点。如何使用简单的方法将每个分数相加,然后除以学生人数 (num_students)?

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==")
   num_students = int(input("Please enter number of students:"))
   print ("you entered ",num_students," students")
   student_info = {}
   student_data = ['Maths Score: ']
   for i in range(0,num_students):
      student_name = input("Name :")
      student_info[student_name] = {}
      for entry in student_data:
        student_info[student_name][entry] = int(input(entry)) 
   print (student_info)
else:
  print("No way, Jose!")
Run Code Online (Sandbox Code Playgroud)

python dictionary average

2
推荐指数
1
解决办法
9751
查看次数

标签 统计

average ×1

dictionary ×1

python ×1