7. Variance


#1

Can anyone tell me whats wrong with this code pls :)?

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


#2

Assuming the formatting is correct, I'm not seeing any issues.


#4

There is nothing wrong with your code. It works as expected if you're having issues can you please post the code with the error message with indentations as shown or a screenshot?


#5

sure thank you!!


#6

You have an indentation error on return total_variance. You need to take away the indentation there also remove the double space between return and total_variance.


#7

Here is the code I have in there. This is your code in the editor. I used slightly difference code for my own when I solved it. :slight_smile:


#8

It worked!!!

Thanks so much :smile:


#9

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