user2742080
user2742080

Reputation: 43

Why the following code results in error?

It works for Employee and calculate_wage, but returns an error when I try to create an instance of PartTimeEmployee and call to the calculate_wage method of PartTimeEmployee's parent class.

class Employee(object):
     """Models real-life employees!"""
     def __init__(self, employee_name):
         self.employee_name = employee_name

     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 20.00

 class PartTimeEmployee(Employee):
     def __init__(self, employee_name):
         self.employee_name = employee_name
     def calculate_wage(self, hours):
         self.hours = hours
         return hours * 12.00
     def full_time_wage(self, hours):
         return super(PartTimeEmployee, self).calculate_wage(self, hours)

 milton = PartTimeEmployee("Milton")
 print (milton.full_time_wage(10))

Upvotes: 0

Views: 150

Answers (1)

Nils Werner
Nils Werner

Reputation: 36849

return super(PartTimeEmployee, self).calculate_wage(self, hours)

is incorrect, it should be

return super(PartTimeEmployee, self).calculate_wage(hours)

And next time: Also post the error message you're seeing.

Upvotes: 5

Related Questions