I have a bit of trouble in calling the other function. When I call grades_sum, I expect my second function to use the variable total but it is not able to and gives the following error message -

Traceback (most recent call last):
File "python", line 16, in
File "python", line 13, in grades_average
NameError: global name 'total' is not defined

I expect to use the variable total

[100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):
    total = 0
    for i in scores:
        total += i
    print total
    return total

def grades_average(grades):
    #average = total/float(len(grades))
    print total/float(len(grades))
    return total/float(len(grades))


total has a local scope, it only exist inside the grades_sum function

grades_sum returns the total, we can capture what the function returns by storing it in a variable, you know how to do this?


is it by saying

from grade_sum import total



that is importing modules/functions.

to capture what a function returns we need to call the function and store result of calling the function in a variable


Awesome! That works!!

Thank you!