# The variance

#1

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

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

#2

Hi, @zagozoe ,

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

``variance = variance/(len(scores))``

Should it be part of the loop?

#3

yes in the insturctions it says :

Divide the total variance by the number of scores.

#4

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.

#5

thanks a lot man that helped me a lot

#6

I had the exact same problem xD

#7

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