Part of the Whole Error


My code:`


What problem? Why and how can I fix?




The indentation of your 'return' statement is incorrect. Where you placed the 'return' is only allowing the first bit in the loop. Try putting this line on the same level as the for loop. That way, the loop will complete and your function will return its result. Python uses indentations to place codes in blocks.

Here is the proper indentation:

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

Hope that helped.


Thanks for your help!
welcome to Hanoi - Vietnam, i'm going to make a cup of coffee for you!


The important bit to understand (@carl1n covers it for a bit) is that a function ends, the moment a return keyword is reached, as explained by carl1n this happens in the first run of your loop. By changing the indent of the return, the return is reached after the loop is finished running.

For anyone who is interested, how to make indent show on the forum:



If you feel that your question was solved, do not forget to mark it as solved.
This helps other students who may have the same question you had.