【发布时间】:2017-04-12 15:53:18
【问题描述】:
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]
}
# Add your function below!
def average(numbers):
total=sum(numbers)
total=float(total)
total/len(numbers)
return total
print total
test = lloyd['homework']
average(test)`
当我测试平均值时,它的返回值与 varaible=float(variable)/len(variable2) 不同
对不起,我是新手,格式不好
【问题讨论】:
-
total/len(numbers)什么都不做。你的意思是total/=len(numbers)吗? 那个会起作用 -
total/len(numbers)你没有存储这个结果(这是你想要的)。
标签: python dictionary