It's Okay To Be Average, but not to return


#1

So I'm stuck on "It's Okay To Be Average", but for some reason, it throws the error

File "python", line 24
return total
^
SyntaxError: invalid syntax

Whenever I run the code. I don't get why, as I am using the correct syntax to return the variable, as far as I know, since I've used it before and it never threw an error. Maybe it's how I tried to simplify the code by setting total directly to the average, but it was the only way I could figure to do it.

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

average(numbers)
{
total: float(sum(numbers)) / len(numbers)
return total
}

#2

The return total error is a bit misleading. It's not actually the problem here.

First, you have to make sure you're using the correct syntax to define the average function, and then also make sure you're using the correct syntax to set the total variable.


#3

Hmm, so it's throwing the wrong error? If so, do you know what the right error would be?


#4

If you remove the return total line temporarily, that should give you a different, more accurate error.


#5

Hi there,
You use wrong syntax. Your code:

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


#6

This is my code. I am getting this error : " File "python", line 32
return: 0.1 * average(student["homework"]) + \ 0.3 * average(student["quizzes"]) + \ 0.6 * average(student["tests"])
^
SyntaxError: invalid syntax"

Why?

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

Add your function below!

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

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["test"])

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

#7

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