# Part of the role - string indices must be integers

#1

Hello! I’m having trouble with the Part of the role exercise. Can you guys help me?

When calling the function get_class_average() with a list as a parameter, I get the following error: string indices must be integers. From what I’ve understood, this means that my average() function is not expecting a string as an argument. Problem is, I know not how to solve this.

I want to be able to use the students list, mentioned in the exercise instructions, as a valid parameter to the get_average() function, called via the get_class_average() function.

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

def get_average(student):
homework = average(student['homework']) * 0.1
quizzes = average(student['quizzes']) * 0.3
tests = average(student['tests']) * 0.6
print(homework + quizzes + tests)
return homework + quizzes + tests

if(score >= 90):
return 'A'
elif(score <= 90 and score >= 80):
return 'B'
elif(score <= 80 and score >= 70):
return 'C'
elif(score <= 70 and score >= 60):
return 'D'
elif(score <= 60):
return 'F'

def get_class_average(class_list):
results = []
for i in range(len(class_list)):
results.append(get_average(class_list[i]))
return average(results)

#edit: Included the function call I attempted.
get_class_average([‘alice’])

``````

#2

please show me the function call you attempted, its not present in your code

#3

Sorry! Here it is:
get_class_average([‘alice’])

The codeacademy exercise attempts the same call.

Thanks =)

#4

`'alice'` shouldn’t be a string, it should be the dictionary:

``````get_average('alice') # error
get_average(alice) # correct
``````

as get_class_average calls get_average with a string, you get an error. as you can see if you run the above code.

#5

Thanks for pointing it out!

#6