Object-Oriented Programming - Create a Game Using Classes and Objects

Hi all,
I am currently working on the " Create a Game Using Classes and Objects" -project but I am stuck because when I try to create an instance of Student (student_one), I get a syntax error. What am I doing wrong?


class Student: def __init__ (self, name, year, likes_math): self.name = name self.year = year self.likes_math = likes_math self.mentees = [] self.subjects = [] def be_mentor(self, other_student): if (self.year >= other_student.year and self.likes_math == True and other_student.likes_math == False): print ("{name} can be {other_student}'s mentor".format(name = self.name, other_student = other_student.name) ) self.mentees.append(other_student) else: print ("{name} cannot be {other_student}'s mentor".format(name = self.name, other_student = other_student.name) student_one = Student("Mark", 7, True) student_two = Student("Tim", 6, False) student_one.be_mentor(student_two)

Classic interpreter/compiler mistake. You get told there’s a syntax error in a line that seems fine. But that’s because the syntax error appears on the line before.

To understand why this is, when tokens are being parsed if you have an open parenthesis, it needs to look for the next closing parenthesis unless it runs into an invalid token in-between.

In this case we have (some expressions and then identifier and =, which is syntactically incorrect, given the placement of the identifier and the assignment operator.

That’s a very long-winded way to say you’re missing a closing parens.

1 Like

Thank you so much @toastedpitabread ! Yes, I can see my mistake now