这里是需要从dictionaries中求平均数,详情点击
codecademy的instruction:
0.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.
Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total.
2.use float() to convert total and store the result in total.
3.pide total by the length of the numbers list. Use the built-in len() function to calculate that.
4.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):
numbers = [lloyd]
sum(numbers):
total = 0
total += total
float(total)
aver = total / len(numbers)
return aver
求教各位,这段代码该如何修改才是正确的?
谢谢大家!!
这个instruction写得很清晰了其实...
代码实现是: