Error in formula Variance

#1

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

Correct formula should be:
(score - average) ** 2

Mathematical formula:

(1/Number of occurrences) * Summation (sigma symbol) i = 1 to Number of occurrences (xi - average) **2

Code:

``````def grades_variance(scores):
variance = 0

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

#2

#3

Yes, it returns float.

#4

What error message are you getting?

#5

Way to go!
No error.

#6

Then I don't understand the issue. Are you referring to the order of subtraction?

Think about it... `(a - b) ** 2 == (b - a) ** 2`

It doesn't matter the order, the outcome is still the same. That is the purpose of squaring. Recall that variance is sigma squared (sigma being standard deviation).

#7

It is possible, but after entering the code by the formula, program works.
Previously showed errors.
(Something like: code returns 0.27485..... but expected 7.264855.....)
I switched it and then it worked.

Maybe parser error.

#8

Is this the exercise with four functions?

``````grades_sum