Help finishing Python Lesson 9.9 Exam Statistics


I have triple checked my code and have run it in and it works fine. but Codecademy keeps spinning and spinning as if in a loop when I run it. Is this a bug or am I completely off???

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

def grades_sum(scores):
  total = 0
  for i in scores:
  		total += i      
  return total

def grades_average(grades_input):
  average = 0
  average = grades_sum(grades_input)/float(len(grades_input))
  return average

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

def grades_std_deviation(variance):
  variance = variance ** 0.5
  return variance

variance = grades_variance(grades)

print grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(variance)


variance is undefined.

print grades_std_deviation(grades_variance(grades))


thanks for the help. I saw this detail on a previous thread from a month ago and tried it too. I still cant stop the infinite loop. It actually begins on lesson 9/7 for variance. When I run that it infinite loops, and for some reason let me click NEXT. on lesson 8 too. then on 9/9 I cant get to click NEXT. been working on this for weeks now


Please post a link to the exercise. Thanks.



I can get lesson 9/5 to run. the 9/6 is just a run the print line. 9/7 “Variance” is where the bugginess begins for me


Just a note that pertains to this module/exercise, only… The data contains one float, so the return value from grades_sum will be a float. That value will carry all the way through so all return values will be floats. Given this convenient exception, remove the float() function from your code anywhere you may have written it.

Now, were we given all integer data, then we would need to explicitly return a float from grades_sum.

total = float(0)


total = 0.0

will suffice and carry all the way through the other functions.

These are my last six lines…

print grades_sum(grades)
print grades_average(grades)
variance = grades_variance(grades)
print variance
print grades_std_deviation(variance)

The output is as follows:



WOW, you are amazing! that was it!!
I was thinking of that float in the beginning but never realized it could be such a BIG deal!

thanks a lot mtf


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