Part of the whole 8/9


#1

Guys this is my code, could someone help me out?

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

This is my error message: Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str


#2

here:

results.append(get_average(students))

the get_average function is designed to calculate the average of one student. what is students? it is a list contains multiply students, get_average() is not designed to handle that.

(ignoring for a second that the function calls are inside the function)


#3

so, I only had to change students to student... Thanks!
What do you mean with the function calls are inside the function?


#4

but do you also understand why this change is important and how it works?

    print get_class_average(students)
    print get_letter_grade(get_class_average(students))

these function calls (^) are inside the function. Function calls should be outside/after the functions (unless you want recursion, which you don't in this case)


#5

Yes because otherwise get_average would try to take several arguments at once and not after another, right?

ah yes... Thank you again!


#6

one list is still one argument. But i know what you are trying to say, and you are right :slight_smile: well done :slight_smile:

no problemo


#7

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