# Part of a whole: Average is wrong?

#1

Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

The calculated class average is correct but the system wants only Alice's average.
I'm not sure 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]
}

def average(numbers):
total = sum(numbers)
total = float(total)
total = total / len(numbers)
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
weighted_average = 0.1 * homework + \
0.3 * quizzes + \
0.6 * tests
return weighted_average
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
print get_average(lloyd)
print get_average(alice)
print get_average(tyler)

def get_class_average(students):
students = [lloyd, alice, tyler]
results = []
for student in students:
results.append(get_average(student))
return average(results)
print get_class_average(alice)``````

I have no idea what I'm doing wrong

Thanks!

#2

Hi @hanahm92,

Placing this assignment ...

``    students = [lloyd, alice, tyler]``

... within the `get_class_average` function overwrites its `students` parameter, defeating the purpose of that parameter.

#3

Thanks! If I get rid of the list or put it external of the get_class_average function, I get a traceback error.

Traceback (most recent call last):
File "python", line 57, in
File "python", line 55, in get_class_average
File "python", line 27, in get_average
TypeError: string indices must be integers, not str

#4

You have this statement ...

``print get_class_average(alice)``

The `get_class_average` function is designed to handle a `list` as an argument. Therefore, you should place square brackets around `alice` within the parentheses in that statement.

#5

Oh ok, the brackets and the removal of the students list got it to work. Thanks so much!

#6