我已经拆分了一个包含姓名和相应分数的列表,并将它们存储在名为students的词典中。但是有了这些分数,我被要求弄清楚平均分,最低分和最高分。我是初学者和学生,所以一步一步的解释将不胜感激。
def getStatistics(students):
# Initialize properly the values of the average score, minimum score, and maximum score.
average = 0
lowest = True
highest = True
scoreTotal = 0
上面的变量被标记为这种方式的原因是因为在我的main函数中调用了这个函数,它有一个带有这些名称的内置调用。但是每当我去运行程序时,它都不打印任何程序。
# loop through the dictionary, and
# calculate the average score, the highest score and the lowest score
# of the students in the dictionary.
i = 0
for grade in students:
scoreTotal += grade[i]
i = i + 1
average = scoreTotal/i
lowest = min(grade[i])
highest = max(grade[i])
# The function must return back the average, highest and lowest score.
return average, highest, lowest
在主要功能中它有这个:(“nameToMarksMap”是前一部分与词典学生的功能)
average, highest, lowest = getStatistics(nameToMarksMap)
print "Average:", average, "Highest:", highest, "Lowest:", lowest
什么都没有打印,有人可以解释原因吗?我一直都有错误。
答案 0 :(得分:0)
用
完成功能def getStatistics(students)
...
# snip
...
return average, highest, lowest