编程语言
首页 > 编程语言> > python-设计高校人员信息包,并完成测试

python-设计高校人员信息包,并完成测试

作者:互联网

【题目描述】定义一个人员类People,其属性有:姓名、性别、年龄;基于People实现学生类Student,添加属性:学号、入学时间和入学成绩;基于People实现教师类Teacher,添加属性:职务、部门、工作时间;基于Student实现究生类Graduate,添加属性:研究方向和导师,分别定义其中的构造函数和输出函数。程序中定义各种类的对象,并完成测试。 基于以上类利用接口实现在职研究生类 GradOnWork。

程序中定义各种类的对象,并完成测试。
【练习要求】请给出源代码程序和运行测试结果,源代码程序要求添加必要的注释。

 

代码:

class People :
    def __init__(self, name = 'ZhangYuxuan',gender = '男',age=20):
        self.name = name
        self.gender = gender
        self.age = age
    def display(self):
        print("姓名:"+self.name+"\n性别:"+self.gender+"\n年龄:"+str(self.age))
class Student(People):
    def __init__(self,student_id="20193250",into_time="2019-09-01",into_score="100.0"):
        People.__init__(self,name = 'ZhangYuxuan',gender = '男',age=20)
        self.student_id = student_id
        self.into_time = into_time
        self.into_score = into_score
    def display(self):
        print("姓名:"+self.name+"\n性别:"+self.gender+"\n年龄:"+str(self.age)+"\n学号:"+self.student_id+"\n入学时间:"+self.into_time+"\n入学成绩:"+str(self.into_score))
class Teacher(People):
    def __init__(self,post="院长",department="软件工程学院",job_time = "2008-12-03"):
        People.__init__(self, name = 'ZhangYuxuan',gender = '男',age=20)
        self.post = post
        self.department = department
        self.job_time = job_time
    def display(self):
        print("姓名:"+self.name+"\n性别:"+self.gender+"\n年龄:"+str(self.age)+"\n职务:"+self.post+"\n部门:"+self.department+"\n工作时间:"+self.job_time)
class Graduate(Student):
    def __init__(self,research_fields="人工智能",teacher = "Mr.Liu"):
        Student.__init__(self,student_id="20193250",into_time="2019-09-01",into_score="100.0")
        self.research_fields = research_fields
        self.teacher = teacher
    def display(self):
        print("姓名:"+self.name+"\n性别:"+self.gender+"\n年龄:"+str(self.age)+"\n学号:"+self.student_id+"\n入学时间:"+self.into_time+"\n入学成绩:"+str(self.into_score)+"\n研究方向:"+self.research_fields+"\n导师:"+self.teacher)
class GradOnWork(Teacher,Graduate):
    def __init__(self):
        Teacher.__init__(self,post="辅导员",department="软件工程学院",job_time = "2008-12-03")
        Graduate.__init__(self,research_fields="人工智能",teacher = "Mr.Liu")
    def display(self):
        print("姓名:"+self.name+"\n性别:"+self.gender+"\n年龄:"+str(self.age)+"\n职务:"+self.post+"\n部门:"+self.department+"\n工作时间:"+self.job_time+"\n学号:"+self.student_id+"\n入学时间:"+self.into_time+"\n入学成绩:"+str(self.into_score)+"\n研究方向:"+self.research_fields+"\n导师:"+self.teacher)
          

 

 

 

 

 

 

 

标签:__,python,self,高校,age,init,测试,time,into
来源: https://www.cnblogs.com/yuxuan-light-of-Taihu-Lake/p/16139675.html