我是python编程的初学者。在codeacademy 的这个问题中,我需要:
编写一个函数 average,它返回一个只用数字填充的列表的平均值。
这是列表:
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
以下是我的尝试:
students = [lloyd, alice, tyler]
def average(k):
k = a(students)
for x[k] in k:
if x[k] == int:
return average(k) = sum(x[k]) / len(x[k])
我知道为什么x[k]
不起作用,但我也想不出解决方案。