How might the add_grade method yield integers into Pieter’s grades list?

self.grades = []

When I use the add_grade method as defined below

def add_grade(self, grade):
  if type(grade) is Grade:
    self.grades.append(grade)
pieter.add_grade(Grade(100))

and then print out Pieter’s grades list

print(pieter.grades)

I see that Grade(100) has been appended to the list, rather than 100, the integer. I get a result of [<__main__.Grade object at 0x7f6ace7406a0>] when printed out.

How might the add_grade method yield integers into Pieter’s grades list?

If I enter pieter.add_grade(100), it doesn’t satisfy the method because the integer 100 is not of class Grade.

Would I have to add a grade argument into the constructor and then simply append self.grade into the self.grades list? I’m just not sure what solution the exercise wants me to find… A list with content such as [<__main__.Grade object at 0x7f6ace7406a0>] does not strike me as useful.

This is in reference to parts 7 + 8 of the exercise.

One suspects that grade has an attribute we’re not polling.

If it is an instance, then just the name won’t mean much.

Ah yes, I see it should be grade.score. I think there is some confusion over this because the solution given for the exercise defines the method as:

  def add_grade(self, grade):
    if type(grade) is Grade:
      self.grades.append(grade)

when what we really want is:

  def add_grade(self, grade):
    if type(grade) is Grade:
      self.grades.append(grade.score)
19 Likes