Review error


#1


https://www.codecademy.com/courses/python-intermediate-en-7mgOa/2/3?curriculum_id=4f89dab3d788890003000096#


Oops, try again. grades_std_deviation(610.8888888888889) returned 18.2776094147 instead of the correct value 24.7161665492


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 += (average - score) ** 2
    total_variance = variance / len(scores)
    return total_variance
print grades_variance(grades)
        

def grades_std_deviation(variance):
    variance = grades_variance(grades)
    return variance ** 0.5
    print grades_std_deviation(variance)

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


#2

That line should not be indented.

This function takes a number and returns its square root. Pass in the return value of the variance function.


#3

error: Traceback (most recent call last):
File "python", line 31, in
NameError: name 'variance' is not defined


#4

That is the variance function. Sorry I didn't use its given name.


#5

def grades_std_deviation(variance):
    variance = grades_variance(grades)
    return variance ** 0.5
print grades_std_deviation(grades_variance)

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

error: Oops, try again. grades_std_deviation(60.5) returned 18.2776094147 instead of the correct value 7.7781745931


#6

Remember to invoke the function...

grades_variance(grades)

#7

I figured it out before looking at the post thanks!


#8

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