# The Variance - 7/9

#1

Hello, can someone please help me with my code. It's not working for some reason. Thank you

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

total = 0

return average

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

#2

``````def grades_variance(scores):
variance = 0
for n in scores:
variance += ((average - score) ** 2) # <== you said n not score in your loop
return variance / len(scores)``````

#4

I don't understand why it's score tho and not. Can it not whatever i want the variable to be?

#5

You never stated what score is. You did state what scores is (as the function input). And you also stated that n is the items in scores in your for loop statement.

You can use whatever variable name you want so long as you defined it.

You can simply change your n in `for n in scores:` to score.

#6

but like why did it work for "score" but not for "n". I didn't define score either.

#7

Like I mentioned in my first comment:

`````` for n in scores:
variance += ((average - score) ** 2) # <== you said n not score in your loop
return variance / len(scores)``````

You're not using `n` at all even though you defined it in the loop. And you didn't define score either.
You can choose to:
1. change your score to n or

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

(You stated that n is the individual scores in the list, scores. So I don't know why you used score instead of n).
2. change your n to score.

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

Makes more sense to others and maybe yourself.

#8

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