Std Deviation review help


Working on the review and I cannot get this to work. Everything in the last problem worked, but in this problem I can get everything to print but the Std Deviation. Would appreciate any help.

The question:

The error message:

"Traceback (most recent call last):
File "python", line 39, in
File "python", line 34, in grades_std_deviation
NameError: global name 'scores' is not defined"

When I change "scores" to "grades" I get:
"Oops, try again. grades_std_deviation(755.5) returned 334.0710059172 instead of the correct value 27.4863602538 "

Replace this line with your code. 
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

print print_grades(grades)

def grades_sum(grades):
    total = 0
    for grade in grades: 
        total += grade
    return total

print grades_sum(grades)
def grades_average(grades):
    sum_of_grades = grades_sum(grades)
    average = sum_of_grades / float(len(grades))
    return average

print grades_average(grades)

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

print grades_variance(grades)

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


i would recommend to revisit 8. standard deviation, there are some problems with your grades_std_deviation function


This is what I ran in 8. and it was accepted.

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

I actually typed in the below for the review and it was accepted. However the answer was based on my understanding of statistics and completely ignored the instructions.

"print grades_variance(grades) ** 0.5"


that is different from what you have in 9?


variance = grades_variance(grades)
print grades_std_deviation(variance)

shouldn't be part of the function, it are function calls. Place them outside/after the function by removing the indentation


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