# Student become teachers

#1

Hello,

I keep having the same problem and I can't seem to fix it...
I've tried to rewrite my whole code, I went back to check former exercises and i spent like 20 minutes staring at it wondering what little capital or bracket i could have forgotten but I just don't see it with this one.

Here is my code:

``````students = [lloyd, alice, tyler]
def get_average(dictionary):
for student in students:
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)

print get_average(alice)``````

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

if you want to loop over students here:

``for student in students:``

students should also be the function parameter, this way you can loop over any list past into the function as argument.

#3

Oh yes, ofcourse! Such a silly mistake haha!

I changed it to this:

``````students = [lloyd, alice, tyler]
def get_average(students):
for student in students:
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)

print get_average(alice)``````

but now I get this error:

``````'Traceback (most recent call last):
File "python", line 34, in <module>
File "python", line 29, in get_average
TypeError: string indices must be integers, not str'``````

#4

okay, never mind. I should have looked at the exercise first

get_average is get the average grade for one students, so don't use a loop. and from the instruction:

Define a function called get_average that takes one argument called student

the parameter should be student.

#5

Thanks a lot!
I got it right this time!

#6

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