Error in formula Variance


In task is wrong formula.

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



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


Be sure your grades_average function is returning a float.


Yes, it returns float.


What error message are you getting?


Way to go! :slight_smile:
No error.


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).


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.


Is this the exercise with four functions?


(Names may be off).


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