9/9 Exam Statistics: Review not recognizing printed variables



After printing the code for the lesson, everything is printed as it should be, but I get an error stating that:

“It looks like the sum of grades was not printed! Make sure you are printing it on its own line.”

Other than that error message, everything appears to be working correctly. I even calculated everything manually to make sure the printed information was correct and it was, so I don’t know why it doesn’t like the information that was printed. The output is as follows:


Sum of grades: 1045.5

Average grade: 80.4230769231

Grade variance: 334.071005917

Standard deviation: 18.2776094147

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

def print_grades(grades_input):
  print "Grades:"
  for grade in grades_input:
    print grade

def grades_sum(grades_input):
  grade_sum = 0
  for grade in grades_input:
    grade_sum += grade
  return grade_sum

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

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

def grades_std_deviation(variance):
  return variance ** 0.5

print "Sum of grades: {}".format(grades_sum(grades))
print "Average grade: {}".format(grades_average(grades))
print "Grade variance: {}".format(grades_variance(grades))
print "Standard deviation: {}".format(grades_std_deviation(grades_variance(grades)))


Print all of the values on individual lines. Codecademy checks for that result exact result.

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


Oh wow, never would have thought that it was failing because I made the result ‘too’ easily readable! I’ll have to remember that for the future, though I’m certainly still going to be formatting my printed lines because I like knowing at a glance exactly what I’m looking at rather than needing to refer to my code.

On a somewhat unrelated topic, which of the following methods is it best to format strings with?

"My %s text is %s back there!" % ("modified", "hiding")
"My {} text is {} back there!".format("modified", "hiding")

Or is there another way I don’t know about that’s even better?


I do it the good old fashioned way (probably not the best way) of concatenation.

"My "+text+" text is "+text2+" back there!"


Hmm, I hadn’t even really considered doing it that way… I wonder what the benefits and limitations of each of those three ways (and any others not yet mentioned) might be. I’m wondering because I’m trying to develop good habits now while I’m learning the basics so that later, it’s already second nature to be doing things the right way.


Concatenation has worked for me consistently since I started using Python. (4 years)


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