我继承的类(老板)不接受主类(员工)接受的3个参数

时间:2017-05-09 14:31:56

标签: python-2.7

我的代码出了什么问题?当我创建一个新的Boss类时,我似乎无法从员工那里获得所有参数。

months = 6

class Employee(object):

    balance = 0
    company_income = 10000000000000000 

    def __init__(self, first, last, pay):
        self.first = first
        self.last = last
        self.pay = pay
        self.tasks = {}
        self.fullname = "{} {}".format(self.first, self.last)
        self.email = "{}.{}@Otterstad.com".format(self.first, self.last)

    def finishTask(self, task):
        del self.tasks[task]
    def getMonths(self):
        print self.pay * months


class Manager(Employee):

    def __init__(self, first, last, pay):
        super().__init__(first, last, pay)
        self.employees = []
        self.pay += 10000

    def addTask(self, task):
        if len(self.tasks) == 0:
            self.tasks[1] = task
        else:
            self.tasks[len(self.tasks)+1] = task


class Boss(Employee):

    def __init__(self, first, last, pay):
        super().__init__(first, last, pay)
        self.employees = []

    def changeSalary(self, new_salary):
        self.pay = new_salary

    def giveBonus(self, bonus, employee):
        employee.balance += bonus

    def addTask(self, task):
        if len(self.tasks) == 0:
            self.tasks[1] = task
        else:
            self.tasks[len(self.tasks)+1] = task

st1 = Boss("test", "test", 2000000000)

1 个答案:

答案 0 :(得分:0)

您正在以适合Python 3的方式调用Boss.__init__,而不是2.

super().__init__(first, last, pay)中,更改

super(Boss, self).__init__(first, last, pay)

super

同样,在整个代码中将其他调用更改为//given two functions ( in a math way) f1,f2 var compared=f1(0)<f2(0); var intersections=[]; for(range=0;range<1000;range+=0.001){ if(compared!==(f1(range)<f2(range))){ intersections.push(range); compared!=compared; } }