The variance


Oops, try again. grades_variance([2, 6, 9, 3, 2]) returned 1.4056192 instead of the expected: 7.44

def grades_variance(scores):
    average = grades_average(scores)
    variance = 0 
    for score in scores:
        variance += (average - score) ** 2
        variance = variance/(len(scores))
    return variance
    print grades_variance(grades)


Hi, @zagozoe ,

You have this statement contained in the for loop ...

variance = variance/(len(scores))

Should it be part of the loop?


yes in the insturctions it says :

Divide the total variance by the number of scores.


Hi, @zagozoe ,

If you perform that division inside the loop, it will execute during every iteration of the loop. To divide the total variance by the number of scores, the division needs to be done after the loop has completed all its executions, otherwise you are performing the division before you have included all the scores in the total variance.

The statement's degree of indentation, as you have it now, includes it in the loop.


thanks a lot man that helped me a lot


I had the exact same problem xD


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