# Do I divide the total variance by the number of scores inside the loop?

## Question

Do I divide the total variance by the number of scores inside the loop?

The step asking you to divide the total `variance` by the number of `scores` should be done outside of the `for` loop, otherwise your number will be far smaller than it should be because you divide it at each step.
Calculating a variance involves squaring the distance from the average of each score, summing those up, and then, after all that, dividing the summed variance by the number of scores.
In pseudo code, the process looks like this:

``````set variance to 0
for each score:
variance = (distance of score from average) squared
return variance / number of scores
``````

And be sure to `print` the result of calling your function at the end!

1 Like
``````grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

total = 0
for score in scores:
total += score

return average

Variance = 0
for score in scores:
Variance = (score - average) ** 2
return Variance / average  " or Variance / score gives me wrong results"

``````

What do I miss?

This should be accumulating. Use the assignment operator for addition, `+=`.

3 Likes

At the end, you also want the variance/ length of the āscoresā list. The length of the list of scores is not the same as the average of the scores

6 Likes

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

In the āprint_gradesā function, when you print out all grades one by one, how do you remove the āNoneā that is being displayed at the end after all scores have been printed out?

By removing the `print` from the last line. Let the function do the printing as it is written.

If I remove the āprint print_grades(grades)ā line, it loops forever and doesnāt end. I donāt understand what you are saying?

Do not remove the whole line, just the print keyword.

``````def print_grades(grades_input):
``````

Thanks, got it @mtf!

1 Like

Thatās great. Did we get rid of the `None`?

Yes, got rid of it! Thanks @mtf!
I didnāt realize that in cases where we use print inside of a function where we donāt have to use return, we should not use the āprintā statement for calling the function. Got it now, thanks!

1 Like

how do i store something

how do i store something

That just means giving a value to a variable:

``````average = 5
``````

stores 5 as the average.

create a variable `average` and store the result of calling `grades_average(scores)` .
You store the result of the `grades_average` function in the variable `average`:
``````average = grades_average(scores)