Let’s see how the grades varied against the average. This is called computing the variance.

A very large variance means that the students’ grades were all over the place, while a small variance (relatively close to the average) means that the majority of the students had similar grades.



On line 18, define a new function called grades_variance that accepts one argument, scores, a list.

First, create a variable average and store the result of calling grades_average(scores).

Next, create another variable variance and set it to zero. We will use this as a rolling sum.

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

Divide the total variance by the number of scores.

Then, return that result.

Finally, after your function code, print grades_variance(grades).

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?