I created a simple Student list and wish to append manual student objects created, using the method below. It comes up with an error saying it requires an additional argument.
class Student:
def __init__(self, first_name, last_name, student_num, email, pps, middle_name):
self.first_name = first_name
self.last_name = last_name
self.student_num = student_num
self.email = email
self.__pps = pps
self.__middle_name = middle_name
self.student_list =[]
def get_full_details(self):
details = self.first_name " " self.last_name " " str(self.student_num) " " self.email
return details
def add_student(self, student_object):
return self.student_list.append(student_object)
# Creating 4 student objects
student1 = Student("Jimmy", "Mccarthy", 1234, "[email protected]", 8074454, "Edward")
student2 = Student("James", "Flynn", 5678, "[email protected]", 7367736, "Borck")
student3 = Student("Emma", "Mcgath", 9837, "[email protected]", 3455433, "Richei")
student4 = Student("Echo", "O Leary", 4334, "[email protected]", 4333357, "Wei")
Student.add_student(student1)
CodePudding user response:
If you call Student.add_student
, you need 2 arguments: self, student_object
.
You can solve this if you first call the constructor of the class student1 = Student("Jimmy", "Mccarthy", 1234, "[email protected]", 8074454, "Edward")
, then use add_student on student1: student1.add_student(Student("James", "Flynn", 5678, "[email protected]", 7367736, "Borck"))
.