7. Variance


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


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


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?


sure thank you!!


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.


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:


It worked!!!

Thanks so much :smile:


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