设计教师接口,该接口包含教师工资计算方法。应用(一)中的高校人员信息包,设计不同职称的教师类:教授,副教授,讲师,教师的基本信息包括姓名、性别、出生年月、职称、课时工作量等属性。注意学校对教师每月工资的计算规定如下:固定工资+课时补贴;教授的固定工资为5000元,每个课时补贴50元;副教授的固定工资为3000元,每个课时补贴30元;讲师的固定工资为2000元,每个课时补贴20元。
程序中定义各种教师类的对象,并编写程序求这些教师的月工资。
class Teacher: def __init__(self, name, gender, birth, zhicheng, work): self.name = name self.gender = gender self.birth = birth self.zhicheng = zhicheng self.work = work def income(self): if self.zhicheng == "教授": return self.work * 50 + 5000 elif self.zhicheng == "副教授": return self.work * 30 + 3000 elif self.zhicheng == "讲师": return self.work * 20 + 2000 def display(self): print(self.name + self.zhicheng + "的工资:" + str(Teacher.income(self))) class Professor(Teacher): def __init__(self): Teacher.__init__(self, name='QAZ', gender='男', birth="1969-1-1", zhicheng="教授", work=3) class Professor_Fu(Teacher): def __init__(self): Teacher.__init__(self, name='WSX', gender='男', birth="1980-02-02", zhicheng="副教授", work=4) class Instructor(Teacher): def __init__(self): Teacher.__init__(self, name='EDC', gender='女', birth="1993-03-03", zhicheng="讲师", work=7) p = Professor() p.display() pf = Professor_Fu() pf.display() i = Instructor() i.display()
标签:__,教师工资,计算,self,work,init,zhicheng,职称,Teacher From: https://www.cnblogs.com/y1126/p/17329628.html