Why does "results" need to be inside the def?


#1


Hey,

I'd like to understand why result[] needs to be within the def and not outside for the def to work?

Thanks
Carlo


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


#2

Actually outside of the codecademy environment it can work if it is outside or inside,

But in that specific lesson they instruct you to place the result = [] line, inside the function


#3

Thank you for your help!


#4

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