Я изучаю отношения класса, я взял этот пример из: https://python -textbok.readthedocs.io / en / 1.0 / Object_Oriented_Programming.html , но когда я запускаю свой код, у меня есть следующееошибка:
Трассировка (последний последний вызов): файл "/home/mlopezmo/.PyCharmCE2018.1/config/scratches/scratch_9.py", строка 49, в mam1000w = maths_dept.add_course ("Математика 1000"," MAM1000W ", 1) Файл" /home/mlopezmo/.PyCharmCE2018.1/config/scratches/scratch_9.py ", строка 19, в add_course self.courses [course_code] = курс (описание, код курса, кредиты, self) Файл "/home/mlopezmo/.PyCharmCE2018.1/config/scratches/scratch_9.py", строка 29, в init self.department.add_course (self) TypeError: add_course () принимает ровно 4 аргумента(2 дано)
Код ниже:
class Student:
def __init__(self, name, student_number):
self.name = name
self.student_number = student_number
self.classes = []
def enrol(self, course_running):
self.classes.append(course_running)
course_running.add_student(self)
class Department:
def __init__(self, name, department_code):
self.name = name
self.department_code = department_code
self.courses = {}
def add_course(self, description, course_code, credits):
self.courses[course_code] = Course(description, course_code, credits, self)
return self.courses[course_code]
class Course:
def __init__(self, description, course_code, credits, department):
self.description = description
self.course_code = course_code
self.credits = credits
self.department = department
self.department.add_course(self)
self.runnings = []
def add_running(self, year):
self.runnings.append(CourseRunning(self, year))
return self.runnings[-1]
class CourseRunning:
def __init__(self, course, year):
self.course = course
self.year = year
self.students = []
def add_student(self, student):
self.students.append(student)
maths_dept = Department("Mathematics and Applied Mathematics", "MAM")
mam1000w = maths_dept.add_course("Mathematics 1000", "MAM1000W", 1)
#mam1000w_2013 = mam1000w.add_running(2013)
bob = Student("Bob", "Smith")
bob.enrol(mam1000w_2013)