5. It's Okay to Be Average


#1

Hello, I'm having a syntax issue. average == total/len(numbers). I've tried various things to fix it and can't seem to find any solutions.

    "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):
    sum(numbers)
    total = float(sum(numbers)
        average == total/len(numbers)
        return average# Add your function below!

#2

You forgot to close the brackets of float. :slightly_smiling:

total = float(sum(numbers))

Another issue is, that you indented for no reason, but I think that happended on accident when you pasted your code in here :slightly_smiling:
Take those two lines to the same level as sum and total, this should fix it.


#3

Thanks! I fixed both issues and my code looks like below

def average(numbers):
    sum(numbers)
    total = float(sum(numbers))
    average == total/len(numbers)
    return average# Add your function below!

Now I'm getting this error "average([3, 0]) returned instead of 1.5 as expected."
EDIT: Nevermind, there should only be one "=" not two


#4

This won't do anything, since you don't assign it anywhere, let's delete it for now :slightly_smiling:

delete one =, or else you check, if average is total/len(numbers) :

average = total/len(numbers)

This should do it:

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

sorry for not noticing before, that I didn't explain it properly :frowning: