我试图创建一个包含salary和bonus属性的类和另一个包含name和idnum属性的类。有一个小程序,询问轮班是否达到了当年的目标,然后计算出当班主管当年的总收入。每次尝试我都会得到:
文件“C:\Python33\12-2.py”,第53行,在main中
班次1=值班主管。员工('28000.0','2240.0','Ian McGregor','S10001')
AttributeError:类型对象“Shiftsupervisor”没有属性“Employee”
我做错了什么??在
^{1}$
Tags:
您的代码存在以下问题:
ShiftSupervisor
是Employee
的子类。除非我误会,值长是一种雇员,所以雇员是最基本的阶级。轮班主管可能具有专门化Employee类的附加属性。我添加了shift_number
属性来演示这一点。在total_income
方法有点混乱。记住,__salary
和{instance.attribute
的形式来访问它们。在综合起来,您的新代码可能如下所示:
我也有种感觉,你在以某种不该发生的方式,把一个轮班和一个员工纠缠在一起,尽管我可以用我的手指去指指点点。一个班次可能有多个员工,而且一个员工可以轮班工作多个班次,但这肯定取决于您要解决的问题。在
相关问题 更多 >
编程相关推荐