this is my code so far:
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(grades):
average = grades_average(grades)
variance = 0
for x in grades:
variance += (average - x) **2
result = variance / float(len(grades))
return result
print grades_variance(grades)
When I run it i get this error:
Oops, try again. grades_variance([5, 7, 5]) returned 0.1481481481 instead of the expected: 0.8888888889
29.4812243969
None
Not sure what I did wrong, any pointers would be greatly appreciated. Thank you
Update:
After naming the object like the description and playing around a bit with the order of things, I found this that works. So if anyone else has an issue with this problem this should work.
def grades_variance(scores):
average = grades_average(scores)
variance = 0
for score in scores:
variance += ((average - score) ** 2)
return variance / float(len(scores))