下面的代码应该从学生的字典中获取标记列表并计算学生的平均分数.我得到"TypeError:list indices必须是整数,而不是float"错误.
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
# Averege function is given below for calculating avg
def average(lst):
l=float(len(lst))
total = 0.0
#code works till here the error occoured below
for item in lst:
add = int(lst[item])
print add
total+=add
return total//l
print average(alice['tests'])
print alice['tests']
Run Code Online (Sandbox Code Playgroud)