Using inheritance in python

后端 未结 4 1243
轮回少年
轮回少年 2021-01-03 06:36

this is my homework assignment, I saw it posted on the website before, but it looks like it was unsolved and I got a different error message than a person asking that questi

4条回答
  •  天涯浪人
    2021-01-03 07:17

    Yes, your init function does not have variable named salary, which gives error when you passed it in to Employee.init.

    class Executive(Employee):
        def __init__(self, name, wage, yearlyBonus):
            Employee.__init__(self, name, salary) 
    

    when you do this

    executive = Executive("Kerry", 520000, 1040000)
    

    which one correlates to the salary? passed that as the employee init method. Better if you call the Employee constructor with super

    Guessing from this method

    def wage(self):
            return self._salary/26   
    

    Maybe this is what you want (not sure how to account yearlyBonus though)

     class Executive(Employee):
            def __init__(self, name, wage, yearlyBonus):
                Employee.__init__(self, name, wage * 26) 
    

提交回复
热议问题