Standard Deviation


#1




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


I included the variable, but it looks like the variance is not defined?


def grades_std_deviation(variance):
    variance = grades_variance(grades)
    result = 0
    for grades in result:
        variance = variance ** 0.5
        variance = variance / float(len(result))
    return result
print grades_std_deviation(variance)


#2

Why do you have so much going on? You simply just need to return inside of the function grades_std_deviation()

return variance ** 0.5

also, outside of the function need to create the variance variable before you call it:

variance = grades_variance(grades)

Can i see all of your code?


#3

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

def grades_sum(scores):
result = 0
for s in scores:
result += s
return result
print grades_sum(grades)

def grades_average(grades):
average = 0
average = grade_sum(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
result = variance / float(len(scores))
return result
print grades_variance(scores)

def grades_std_deviation(variance):
variance = grades_variance(grades)
result = 0
for grades in result:
variance = variance ** 0.5
variance = variance / float(len(result))
return result
print grades_std_deviation(variance)


#4

I edited my above post, so read it all and it should fix your problem


#5

Thank you! I solved it :slight_smile:


#6

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