Part of the whole


why when I put
students=[lloyd,alice,tyler] out of the function , def get_class_average(students):, then it works? why?


Hi @yokiaayuxi,

This needs to be outside the function ...


.. so that the function parameter does not get overwritten.

If you include it in the function, the function will process [lloyd,alice,tyler] even if a different list is passed to it. That defeats the purpose of the students parameter.


The list is a global object and is not supposed to be created inside the function. Rather it is passed into the function to be enumerated. By writing it inside the function you wipe out the list that the user is passing in as their argument. The SCT sends in [alice] but the return is the result of [lloyd, alice, tyler] every time.

Lesson here? Keep your data outside of your functions and let the parameter do the work on anything it is given.


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