5/9 error


#1

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):
numbers = [lloyd, alice, tyler]
h = float(sum(numbers["homework"])) / len(numbers["homework"])
q = float(sum(numbers["quizzes"])) / len(numbers["quizzes"])
t = float(sum(numbers["tests"])) / len(numbers["tests"])
a = h + q + t
total = float(a) / 3
return total

SAVE ME MY FRIENDS! WHAT'S WRONG HERE?


#2

Write this as the students list, and just below the data dictionaries, not inside a function.

The average function should not be used to calculate the weighted average, only an average of a list of numbers.

This is how it is spelled out in the instructions, I believe...

def average(numbers):
    total = sum(numbers)   # using the sum() function for adding a list
    total = float(total)
    total = total / len(numbers)
    return total

#4

thank you man :slight_smile:


#5

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