Oops, try again. get_average(alice) raised the following error: 'float' object is not iterable


#1

Hi everyone, I'm stuck at the section "Just weight and see".
The error I get is the following
Oops, try again. get_average(alice) raised the following error: 'float' object is not iterable

Please, would anyone with the solution be so kind to help me out with this?
The code I've done is the following:
def get_average(student):
homework=average(student["homework"])
quizzes=average(student["quizzes"])
tests=average(student["tests"])
homework=0.1*homework
quizzes=0.3*quizzes
test=0.6*tests
return sum(homework+quizzes+tests)

Thanks in advance.


#2

Hi, @dataplayer60980 ,

Because your code is not formatted, it is difficult for other users to read and debug it. After code is been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

The problem is here ...

return sum(homework+quizzes+tests)

The expression inside the parentheses, namely homework+quizzes+tests, evaluates to a float. That is what you are passing to the sum function. But the sum function is designed for use with lists and various other iterable objects.

Do this instead ...

return homework + quizzes + tests