# Weight and See

#1

get_average(alice) raised the following error: list indices must be integers, not str

I don't understand why this isn't working. What do I need to change?

``````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 = float(sum(numbers))
result = total/float(len(numbers))
return result

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(students["tests"])
return 0.1 * homework + 0.3 * quizzes + 0.6 * tests``````

#2

There is an issue with the spelling.

#3

Hi, @kayareess6 ,

In this statement ...

``tests = average(students["tests"])``

... you are using a key to try to access the `students` list directly instead of accessing an item in the list, which is represented by the `student` parameter in the `get_average` function header.

#4

As @mtf pointed out, the problem is due to a spelling error. The Python interpreter, however, does not know what you intended to do, and it interpreted the error as an attempt to use the string, `"tests"`, as an index to access the global `students` list.

But, what might be most puzzling is that if you examine your code, you won't find the global `students` list. Codecademy, however, still has that list in memory from earlier exercises, such as 3: Put It Together. To avoid potential problems in later exercises, you should add this statement in again, right after the `tyler` dictionary ...

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

#5

Thanks a ton for the help!! I really appreciate it.

#6

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