# Stuck on review

#1

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

total = 0

return average

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

return variance

I get the error "Oops, try again. grades_std_deviation(1524.6666666666667) returned 18.2776094147 instead of the correct value 39.0469802503" for the above code.

I suspect that it's due to the fact that for the function grades_std_deviation(variance), variance is always equal to grades_variance(grades) ** 0.5 regardless what the input is.
However, I am not able to find a solution to solve this problem.
Can anyone offer some help please?

#2

Seamantically, this makes more sense to me:

``average = float(sum_of_grades) / len(grades)``

since the sum is likely to be a float. `len()` is a counting number so one would never think of it as a float. Not the problem, though. Just pointing this out.

Technically, since this is a function chain, the most logical place to declare the float is in the first function in the chain.

``total = 0.0``

or

``total = float(0)``

Now all values being passed around will be floats.

This is the problem function. You are not returning the square root of the value passed in to the parameter.

#3

Thanks your for help mtf, but can you elaborate more on the problems of the last function? I still dont quite understand it.

#4

return variance ** 0.5
print variance

I have found a correct version of the code.
However, I could not understand what happens here:
"return variance ** 0.5
print variance"

why would you return the value before you define variance as grades_variance(grades).

I hope someone can help me clarify this for me. THanks.

#5

`grades_variance` returns sigma squared.

`std_deviation` should return just the square root, or sigma.

``````def grades_std_deviation(variance):
return variance ** 0.5``````

#6

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