The help for 'The Variance'


#1

Can anyone debug my code!? An error is popping up again n' again, I think it really needs to relax :stuck_out_tongue:


#2

Not clear in picture so here's the main part of code:

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

print grades_variance(grades)

...and here's the error:

Oops, try again. grades_variance([0, 5, 5, 0]) returned 1.5625 instead of the expected: 6.25


#3

By the looks of things you have a problem with the indentation of the 'return' command, it should be out of the 'for' loop:

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

not

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

Hope this helped :slightly_smiling:


#4

your code is absolutely fine it has only indentation problem
your return statement should be indented just below for loop..
it will run the code