I'm guessing that you want to pass a list of grades to your average()
function.
You have the syntax a bit mixed up in grades.sum() = total
and total.float() = total
You (probably) want something like this:
def average(grades):
total = sum(grades)
return float(total) / len(grades)
And you'd call that function like this:
avg = average(alice["homework"])
total = sum(grades)
says calculate the sum of the values in grades
and store the result in a variable named total
. The function call sum(grades)
asks a question, and in Python (like most other programming languages) we write the question on the right side of the =
sign, and the place to put the answer goes on the left side of the =
sign. But your code has that backwards.