Oops, try again error on Standard Deviation exercise


#1


Pretty sure the problem here will be something like the other 2 posts I've made, the shell is testing other numbers but the call is throwing something off and I don't understand what it is.


The error I get is below, the return the correct one for the actual grades list.

Oops, try again. grades_std_deviation(12.6666666667) returned 18.2776094147 instead of the expected: 3.559026084


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

def print_scores(scores):
    for grade in scores:
        print grade

def scores_sum(scores):
    total = 0
    for grade in scores: 
        total += grade
    print "Sum: ",total
    return total
    
def scores_average(scores):
    sum_of_scores = scores_sum(scores)
    average = sum_of_scores / float(len(scores))
    print "Average: ",average
    return average

def scores_variance(scores):
    num = len(scores)
    average = scores_average(scores)
    var = 0
    for score in scores:
        var += float(average - score) ** 2
    print "Variance: ",var/num
    return var/num

def scores_std_deviation(variance):
    return variance ** 0.5

variance = scores_variance(grades)

print scores_std_deviation(variance)


#2

in exercise 7 you should have created grades_variance function, yet you called it scores_variance.

In this exercises you don't have the freedom to change the function names to your liking. same in exercise 8 where you are currently stuck, you decide to name the function differently


#3

I'm not sure how that would matter as everything is calling the right function names, but I fixed it and I'm still getting the same error

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

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

def grades_sum(scores):
    total = 0
    for grade in scores: 
        total += grade
    print "Sum: ",total # Sum check
    return total
    
def grade_average(scores):
    sum_of_grades = grades_sum(scores)
    average = sum_of_grades / float(len(scores))
    print "Average: ",average # Average check
    return average

def grade_variance(scores):
    num = len(scores)
    average = grades_average(scores)
    var = 0
    for score in scores:
        var += float(average - score) ** 2
    print "Variance: ",var/num # Variance check
    return var/num

def scores_std_deviation(variance):
    return variance ** 0.5

variance = grades_variance(grades)

print scores_std_deviation(variance)

#4

but if the exercise is going to call the function for validation purposes, they should be named correctly:

def grade_average(scores):

should be:

def grades_average(scores):

this:

def grade_variance(scores):

should be:

def grades_variance(scores):

this:

def scores_std_deviation(variance):

should be:

def grades_std_deviation(variance):

this:

print scores_std_deviation(variance)

should be:

print grades_std_deviation(variance)

#5

OK, I see the problem now.

Thank you for the help!


#6

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