The Varience



Could you please guide me to the right direction?

I am kinda lost with a variance function:

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

def print_grades(n):
    for i in n:
        print i

def grades_sum(n):
    for i in n:
        return sum(n)
def grades_average(n):
    return grades_sum(n) / float(len(n))
print grades_average(grades)
def grades_variance(n):
    average = grades_average(n)
    variance = 0 
    for i in n:
       variance = (average - i) ** 2
    return variance / len(n)

print grades_variance(grades)


for the fact that you are lost, you are pretty close, here:

variance = (average - i) ** 2

variance should be increased, currently you just overwrite variance each iteration of the loop, so the variance your grades_variance calculates is of the last value in n list

from the instructions:

for each score in scores: Compute its squared difference: (average - score) ** 2 and add that to variance.

the important word is add, currently you just overwrite value in variance variable


Thank you. Just had to add +
The "add" word lost me completely as I thought it means store it in variable instead of adding it up.

Thanks for help. Much appreciated.