Review exercise for "Class" for python beginner lecture

what is the point of making the grades list for the constructor? and how can I access this list? I am having trouble understanding why the list is necessary since I can’t seem to access it.

Hi and welcome to the forums!

The reason that grades is initialised as an empty list is so that you can actually append grades to that list. If we don’t make it in the constructor then there won’t be any list to add to and as such the code will not work.

As for accessing the list you can definitely do so. If you run the codebyte below, you will see that when a couple of grades have been added, you can print out these grades by looping through the grade list.

class Student: def __init__(self, name, year): = name self.year = year self.grades = [] def add_grade(self, grade): if type(grade) is Grade: self.grades.append(grade) class Grade: minimum_passing = 65 def __init__(self, score): self.score = score def is_passing(self): if self.score >= self.minimum_passing: return print("pass") else: return print("fail") dave = Student("Dave Pikey", 2004) english = Grade(80) maths = Grade(63) dave.add_grade(english) dave.add_grade(maths) for grade in dave.grades: print(grade.score)

We can see that the two scores print out from the grades list in the order they were added. Hopefully this helps but if you still have questions please do ask and I’ll be happy to clarify.