Part of the whole


Just can't see what's wrong with my code, scratching my head.

def get_class_average(students):
    results = []
    for student in students:
        return average(results)

error: get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected

Tried variations but I'm lost.


a function ends the moment a return keyword is reached

so your function ends in the first iteration/run of the loop, so your function won't calculate the correct class average for a class of 2 or more students.


thank you! I feel so stupid now haha.

as simple as changing the indentation of the return call for anyone else as silly as me.


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