2024/5/12
所花时间:1小时
代码行:70行
博客量:1篇
了解到的知识点
# 定义人员类 People
class People:
def _init_(self, name, gender, age):
self.name = name
self.gender = gender
self.age = age
def display(self):
print(f"Name: {self.name}, Gender: {self.gender}, Age: {self.age}")
# 学生类 Student
class Student(People):
def _init_(self, name, gender, age, student_id, admission_date, admission_score):
super()._init_(name, gender, age)
self.student_id = student_id
self.admission_date = admission_date
self.admission_score = admission_score
def display(self):
super().display()
print(f"Student ID: {self.student_id}, Admission Date: {self.admission_date}, Admission Score: {self.admission_score}")
# 教师类 Teacher
class Teacher(People):
def _init_(self, name, gender, age, position, department, years_of_service):
super()._init_(name, gender, age)
self.position = position
self.department = department
self.years_of_service = years_of_service
def display(self):
super().display()
print(f"Position: {self.position}, Department: {self.department}, Years of Service: {self.years_of_service}")
# 研究生类 Graduate
class Graduate(Student):
def _init_(self, name, gender, age, student_id, admission_date, admission_score, research_area, advisor):
super()._init_(name, gender, age, student_id, admission_date, admission_score)
self.research_area = research_area
self.advisor = advisor
def display(self):
super().display()
print(f"Research Area: {self.research_area}, Advisor: {self.advisor}")
# 在职研究生接口 GradOnWork
class GradOnWork:
def _init_(self, job_title, company):
self.job_title = job_title
self.company = company
def display(self):
print(f"Job Title: {self.job_title}, Company: {self.company}")
# 测试类的创建和输出
student1 = Student("niumo19", "男", 20, "20223683", "2022-09-01", 95)
teacher1 = Teacher("niumo20", "男", 35, "教授", "软件工程", 10)
graduate1 = Graduate("niumo21", "男", 25, "20223689", "2021-09-01", 85, "Machine Learning", "niumo20")
grad_on_work1 = GradOnWork("Data Scientist", "Tech Company")
print("Student Information:")
student1.display()
print("\nTeacher Information:")
teacher1.display()
print("\nGraduate Information:")
graduate1.display()
print("\nGraduate on Work Information:")
grad_on_work1.display()