Part of the whole


#1

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

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

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

Tried variations but I'm lost.


#2

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.


#3

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.


#4

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