Exam Statistics: The Variance


#1

Hi when i run the code i get the following error

Oops, try again. grades_variance([4, 5, 5, 7, 8, 8, 2, 6, 2]) returned 0.1659807956 instead of the expected: 4.6172839506

I am really confused on what i have done wrong!!

any help is greatly appreciated

Thanks

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

#2

Sure!!

The statement where you are giving a value to a...a = variance / len(scores)

len(scores) should be --> float(len(scores))

you will need to do that for every -> len(scores) || len(grades)

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
    result = variance / float(len(scores))
    return result

#3

thanks that has solved it!!!! :slight_smile:


#4

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