0
votes
class Student:
  def __init__(self,first,last,id):
    self._first_name = first
    self._last_name = last
    self._id_number = id
    self._enrolled_in = []

  def enroll_in_course(self,course):
    self._enrolled_in.append(course)
    return self._enrolled_in()

s1 = Student("kathy","lor","323232")

s1.enroll_in_course("hello")

print(s1._enrolled_in)

In the code above, i am getting the error as:

Traceback (most recent call last):
File "main.py", line 14, in s1.enroll_in_course("hello") File "main.py", line 10, in enroll_in_course return self._enrolled_in() TypeError: 'list' object is not callable

I am trying to solve the error, but unable to do so. Can anybody help me here.

3
I think you meant to use _enrolled_in on line 9 - Adithya
i have corrected that minor mistake. @Adithya - Jonardan Cena
you have to ask new question now for another error. - PIG

3 Answers

0
votes

You have defined self._enrolled_in but you're adding it to self.enrolled_in

Missed the underscore (self._enrolled_in.append)

0
votes

You have called the attribute _enrolled_in in your __init__() method. In the enroll_in_course() method you're trying to append to enrolled_in which does not exist. So try by adding the underscore in front.

0
votes

You are missing an _ in the appended statement. You should write self._enrolled_in.append(course) on your enroll_in_course method.