Part of a whole


#1



Oops, try again. get_class_average([alice]) resulted in an error: global name 'student' is not defined


Not sure why I am getting this error, I have followed exactly how others have done in the past.


def get_class_average(students):
    results=[]
    for stundent in students:
        return results.append(get_average(student))
    return average(results)


#2

Ok so I see I spelt STUDENT as "stundent" so after fixing that I now got this error ....

Oops, try again. get_class_average([alice]) should return a number

How do I fix this?


#3

Here:

remove the return keyword.

Let me know if this resolves. :wink:


#4

Thanks, that worked, can you explain what it was doing with the return there and now what it is doing with it gone.


#5

It was returning (exiting the function) on the first iteration. It should be accumulating (appending) list elements until the loop is finished.


#6

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