General advice: TypeError: list indices must be integers, not str


#1

I get the same error message nearly every time I make a mistake, and I simply don't understand what it is referring to. What are the indices? Why do they have to be integers? How do I go about problem solving this when I run into this error? My code is below. It is mostly from "Just Weight and See", but I added the section at the end for practice and ran into my now most hated and completely unhelpful error message:

Traceback (most recent call last):
File "python", line 37, in
File "python", line 28, in get_average
TypeError: list indices must be integers, not str

Can anybody help break this down? Thanks!

code starts here

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

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
homework = homework * .1
quizzes = quizzes * .3
tests = tests * .6
return homework + quizzes + tests

error somewhere below

person = ["lloyd", "alice", "tyler"]
grade = get_average(person)
print grade


#2

You are assigning person to three strings, rather than the correct variables.


#3

what would be the correct variables (and why)?


#4

The correct variables would most likely be:

lloyd
alice
tyler

Do you know what your problem was?