Phyton/
Создать иерархию классов для описания академии.
Примерный список классов: Person, Teacher, Student, Subject, Academy и тд.
Продумать архитектуру: реализовать принципы ООП
Помогите решить задание.
Ответы
Ответ:
class Person:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class Teacher(Person):
def __init__(self, name, age, gender, subject):
super().__init__(name, age, gender)
self.subject = subject
def teach(self):
print(f"{self.name} is teaching {self.subject}")
class Student(Person):
def __init__(self, name, age, gender, courses):
super().__init__(name, age, gender)
self.courses = courses
def enroll(self, course):
self.courses.append(course)
class Subject:
def __init__(self, name, description, teachers):
self.name = name
self.description = description
self.teachers = teachers
class Course:
def __init__(self, name, description, students, teachers):
self.name = name
self.description = description
self.students = students
self.teachers = teachers
class Academy:
def __init__(self, name, courses, teachers, students):
self.name = name
self.courses = courses
self.teachers = teachers
self.students = students
Объяснение:
def __init__(self, name, age):
self.name = name
self.age = age
class Teacher(Person):
def __init__(self, name, age, subject):
super().__init__(name, age)
self.subject = subject
class Student(Person):
def __init__(self, name, age, grade):
super().__init__(name, age)
self.grade = grade
class Subject:
def __init__(self, name, teacher):
self.name = name
self.teacher = teacher
class Academy:
def __init__(self, name):
self.name = name
self.teachers = []
self.students = []
self.subjects = []
def add_teacher(self, teacher):
self.teachers.append(teacher)
def add_student(self, student):
self.students.append(student)
def add_subject(self, subject):
self.subjects.append(subject)