# 7/9 exam statistics

it keeps erroring
<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
Oops, try again. You did not print the correct variance. Double-check your code and make sure you print the variance!

<What do you expect to happen instead?>

```python

Replace this line with your code.
grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

total = 0

return average

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

``<do not remove the three backticks above>``

This line needs to be on the same indentation level,

as this line,

And on the last line ater your return statement you should have this, but it needs to be outside your function.

``````
``````

Not just, print variance

Hi, I think if you put this code:

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

inside the loop, it will give wrong result, except you change the variable name to something else.

ex:

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

in your code, you just need to call the function as @bandit said at the end outside the function.

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

``````

Please correct me if i am wrong.

why do i need to use another variable for this “variance=variance/len(scores)” part?

or perhaps the value of variance in that part isnt zero?

if you put it inside the loop and do not change the variable, when it start the second loop, the value of variance will be from the result of this code:

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

``````variance += (average - score) ** 2
``````

Sorry, idk how to explain properly:

Here is some code that show the result will be different.

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

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

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