파이썬 클래스 상속 관련 질문입니다!
조회수 231회
해당 코드에서 Professor와 Student 클래스는 School 부모클래스에 속해있는 자매 클래스입니다. 코드 아래의 인풋 값에서 Jane.matchProfessor(Edison)이 입력되었을 때, Professor 클래스의 Edison을 나오게 수정할 수 있는 방법이 궁금합니다...
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())
댓글 입력