# 8. Part of the whole

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
Hello! I was hoping someone might be able to pick out why I am receiving this error message

“Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str”

I’m thinking it may have to do with something earlier in my code so I linked it all below. Any feedback would help.

<What do you expect to happen instead?>

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

def get_average(student):
homework = average(student[“homework”])
quizzes = average(student[“quizzes”])
tests = average(student[“tests”])
return (homework *.10) + (quizzes *.3) + (tests *.6)

if score >=90.0:
return “A”
elif score >=80.0:
return “B”
elif score >=70.0:
return “C”
elif score >=60.0:
return “D”
else:
return “F”

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

``<do not remove the three backticks above>``

#2

your students are not strings, they are variables of dictionary type , so in the above list you should skip the quotes “”
students = [lloyd,alice,tyler]

#3

@cawleye4gmail.com

No need of putting double quotes since the variables already exists.

#4

Thanks for pointing that out, made the change but still receiving same error message.

#5

I checked my task and I don’t have this code line at all. Can you remove that line or at least move it outside from get_class_average(students) function definition?

#6

Yes, I got rid of it and also fixed get_average(students) to be get_average(student) so now my code looks like …
def get_class_average(students):
results=
for student in students:
get_average(student)
results.append(get_average(student))
return average(results)

But now I receive this error message…

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

#7

your code is correct , all i did that i move the list outside the function , so try it and reply to me

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

#8

Thanks for the help, I did as you said. I’m still receiving this error message “get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected”

It seems like for some reason it isn’t calling tyler? Not sure…

#9

this is your code and it work for me !!!
can you see any diffrence ??

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

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

if score >=90.0:
return "A"
elif score >=80.0:
return "B"
elif score >=70.0:
return "C"
elif score >=60.0:
return "D"
else:
return "F"

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

#10

Hi can you try to put your students array outside the function `get_class_average`

#11

no difference! But I cut everything and pasted it back in and it worked perfectly. Who knows! Thanks for the help!

#12

beside that we move out the list , you can see that you forgot indentation for `return average(results)`
no thanks