# Just Weight and See

#1

What am i doing wrong i am getting this error message: Oops, try again. get_average(alice) raised the following error: 'float' object is not iterable

``````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]
}

def average(numbers):
total = float(sum(numbers))
result = total / len(numbers)
return result

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return sum(homework * .1) + (quizzes * .3) + (tests * .6)``````

#2

I can't help with the explanation, but this is what I did to make it work.

def get_average(student):
homework = 0.1 * average(student["homework"])
quizzes = 0.3 * average(student["quizzes"])
tests = 0.6 * average(student["tests"])
return (homework + quizzes + tests)

#3

maybe having the sum() in the last line? try and remove it, or to have a parenthesis for it around the entire line, not just the homework function. youroperatorhere looks cleaner/wiser than what i came up with, but heres what i got:

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (.10 * average(student["homework"])) + (.3 * average(student["quizzes"])) + (.6 * average(student["tests"]))

#4

the sum function only takes integers, math.fsum() takes floats. you could simply return (homework*.1 + quizzes*.3 + test*.6)

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.