假设教师工作证包括编号、姓名、性别、出生年月、职务和签发时间;学生 证包括编号、姓名、性别、出生年月、系别、入校时间。请你为教师工作证与学生工作证设计一个类结构,尽可能保证代码的重用率,并输出教师工作证和学生工作证信息。
时间: 2023-05-16 09:06:06 浏览: 240
好的,根据您的需求,我可以为您设计一个类结构,如下所示:
class WorkCertificate:
def __init__(self, id, name, gender, birth, issue_time):
self.id = id
self.name = name
self.gender = gender
self.birth = birth
self.issue_time = issue_time
class TeacherCertificate(WorkCertificate):
def __init__(self, id, name, gender, birth, issue_time, position):
super().__init__(id, name, gender, birth, issue_time)
self.position = position
class StudentCertificate(WorkCertificate):
def __init__(self, id, name, gender, birth, issue_time, department, admission_time):
super().__init__(id, name, gender, birth, issue_time)
self.department = department
self.admission_time = admission_time
# 输出教师工作证信息
teacher = TeacherCertificate("001", "张三", "男", "1990-01-01", "2021-01-01", "教授")
print("教师工作证信息:")
print("编号:", teacher.id)
print("姓名:", teacher.name)
print("性别:", teacher.gender)
print("出生年月:", teacher.birth)
print("职务:", teacher.position)
print("签发时间:", teacher.issue_time)
# 输出学生工作证信息
student = StudentCertificate("002", "李四", "女", "2000-01-01", "2021-01-01", "计算机科学与技术", "2020-09-01")
print("学生工作证信息:")
print("编号:", student.id)
print("姓名:", student.name)
print("性别:", student.gender)
print("出生年月:", student.birth)
print("系别:", student.department)
print("入校时间:", student.admission_time)
希望这个类结构能够满足您的需求。
阅读全文