Questions about Python class inheritance!

Asked 2 years ago, Updated 2 years ago, 400 views

In that code, the Professioner and Student classes are sister classes that belong to the School parent class. I wonder how I can modify the Edison of the Professor class to come out when Jane.matchProfessor (Edison) is entered in the input value below the code...

class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

class School(Person):
    def __init__(self, name, age, id):
        Person.__init__(self, name, age)
        self.id = id

class Professor(School):
    def __init__(self, name, age, id):
        Faculty.__init__(self, name, age, id)
        self.student = []
    def matchStudent(self, student):
        self.student.append(student)
    def studentsCount(self):
        if not self.student:
            return "I have no student for this course."
        else:
            return "I have " + str(len(self.student)) + "."
    def studentsName(self):
        if not self.student:
            return "I have no students."
        else:
            return "My students are "+str(self.student)+"."

class Student(School):
    def __init__(self, name, age, id):
        Faculty.__init__(self, name, age, id)
        super().name
    def set_professor(self, prof):
        super().name
        self.Professor.name
    def matchProfessor(self, prof):
    def professorName(self):
        if not self.prof:
            return "I don't have an advisor professor yet."
        else:
            return "My professor is " + str(self.prof) + "."

Edison = Professor("Edison", 50, 612345)
Jane = Student("Jane", 21, 19123456)
print(Jane.professorName())
Jane.matchProfessor(Edison)
print(Jane.professorName())
print(Edison.studentsCount())

python class inheritance

2022-11-22 12:37

1 Answers

When Jane.matchProcessor(Edison) is executed, the set__proessor method of Jane and the Edison method must be executed internally.


2022-11-22 12:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.