你们已经帮过我了:
我需要返回我的平均计算值,但它不起作用
StudentGrades = {
"Alcott": [5, 9, 7],
"Jerry": [3, 5, 2],
"David": [8, 9, 8, 9]
}
## I fixed this, thank you
print("Students:")
for x, y in StudentGrades.items():
print(x, y)
while True:
print("Select a student: ")
name = str(input())
if name in StudentGrades.keys():
print("You have chosen: " + name)
print (res = sum(StudentGrades[name]/len(StudentGrades[name]))
else:
print('You chosen wrong!')
break
## Also, I didn't wrap right John's value, thank you for showing me
#use of update function
print("Original Dictionary:")
print(StudentGrades)
StudentGrades.update(student)
print("Dictionary after update:")
print (StudentGrades)
#John's Average (not working? int object is not iterable)
res = sum(StudentGrades["John"]) / len(StudentGrades["John"])
print("John's average is:[10]/1 =" + str(res))
但我也在想我是否可以退回这样的东西:
#Alcott's average
resAlcott = sum(StudentGrades["Alcott"]) / len(StudentGrades["Alcott"])
print("Students:")
for x, y in StudentGrades.items():
print(x, y)
while True:
print("Select a student: ")
name = str(input())
if name in StudentGrades.keys() == "Alcott":
print("You have chosen: " + name + "'s average is", StudentGrades["Alcott"], resAlcott)
else:
print('You chosen wrong!')
break
谢谢你,我再次感到抱歉
你需要这样的东西:
此外,要添加新学生,不应使用
student = {'Name': 10}
,而应使用student = {'Name': [10]}
。与所有其他值一样,该值必须是一个列表我想你需要在这里做出改变。首先是崩溃
分为两行,并修复括号问题以获得
您需要进行的第二个更改是将更新的学员从
到
这样就可以反复查看他的分数
相关问题 更多 >
编程相关推荐