Std_deviation - 'float' object is not iterable


#1

This is my code, how do I correct this error : The error I get is

Oops, try again. grades_std_deviation(603.4375) raised an error: 'float' object is not iterable.

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

def print_grades(grades):
    for grade in grades:
        print grade

def grades_sum(grades):
    total = 0
    for grade in grades: 
        total += grade
    return total
    
def grades_average(grades):
    sum_of_grades = grades_sum(grades)
    average = sum_of_grades / float(len(grades))
    return average

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

print print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(grades)

#2

lets look at the instructions:

Define a function grades_std_deviation(variance)

you gave your function a different parameter, that is not a very big problem. Just keep it in mind when progressing through the instructions, next step of instructions:

return the result of variance ** 0.5

uhm.. variance was the function parameter, so either change the function parameter or return grades ** 0.5, next step of instructions:

After the function, create a new variable called variance and store the result of calling grades_variance(grades)

you did this step, but not at the right place, look at the instructions again, final step:

Finally print the result of calling grades_std_deviation(variance).

you give your function call a different argument then told by the instructions, on step 3 you should have declared variance (outside the function, not inside the function like you did) which you now need to supply as argument

standard deviation is calculated using the the variance, not the grades


#3

thank you! this worked.

def grades_std_deviation(variance):
    return variance ** 0.5

print grades_std_deviation(grades_variance(grades))

#4