python只有英文版吗_【Python,又有不懂了。这是题目,只有英文的:Writeafunctionaveragethattakesalistofnumbersandreturnstheavera...

Python,又有不懂了。

这是题目,只有英文的:

Write a function average that takes a list of numbers and returns the average.

1. Define a function called average that has one argument, numbers.

2. Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total.

3. Like the example above, use float() to convert total and store the result in total.

4. Divide total by the length of the numbers list. Use the built-in len() function to calculate that.

5. Return that result.

注释后面是我自己写的:

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=0

for numbers in numbers:

total += numbers

return float(total) / len(numbers)

交上去提示错误:

object of type 'int' has no len()

请问应该怎么写才对?谢谢

作业帮用户2017-06-02举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值