5. It's okay to be average


#1



Hi,
What is going wrong here? I can't see it. My error message is: Oops, try again. average([3, 0]) returned 0.0 instead of 1.5 as expected.


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 = sum(numbers)
    total = float() 
    return total % len(numbers)


#2

@berivan28 ,

Why is there no argument in the parentheses here? ...

total = float()

What does the % operator do here, and why are you using it? ...

return total % len(numbers)

#3

It divides total by the length of the numbers?


#4

% is a modulus or remainder operator. You need the / operator.

What should be in the parentheses here? ...

total = float()

#5

I fixed it:

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

Thankyouuu


#6