This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by mysterious.benedict
about 10 years

Confusing error message for 6/9

I’m getting the following error message:

Oops, try again. Did you accidentally delete lloyd, alice, or tyler? Your code threw a “global name ‘lloyd’ is not defined” error.

For the following code:

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(lst):
    return float(sum(lst) / len(lst)
def get_average(student):
    homework_avg = (average(student["homework"]) * .1) 
    quiz_avg = (average(student["quizzes"]) * .3)
    test_avg = (average(student["tests"]) * .6)
    weighted_avg = homework_avg + quiz_avg + test_avg
    return weighted_avg

I’ve also tried writing the get_average function as a single return statement (doing all the math in one line) and got the same error message.

Can anyone help me?

  • List item

Answer 52dd914280ff3301fe000e19

0 votes

Permalink

def average(lst):
return float(sum(lst) / len(lst)

You are missing ) it should be float(sum(lst)) instead

points
Submitted by Michal
about 10 years