14/18 help


#1

I don't know what's wrong with my code

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

Add your code below!

class PartTimeEmployee(Employee):
def init(self, hours):
self.hours = hours
return hours * 12
print hours * 12

def full_time_wage(self,hours):
    return super(ParTimeEmployee,self).full_time_wage(hours)

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


#2

Hi man,

You have:

def full_time_wage(self,hours):
return super(ParTimeEmployee,self).full_time_wage(hours)

Should you have:

def full_time_wage(self,hours):
return super(ParTimeEmployee,self).calculate_wage(hours)

That might do it. Also, do you need to initialise the subclass?


#3

Now that I look at it again, I think you're missing the letter t in there in PartTimeEmployee


#4

Thank you, but it still can not work. And now I change my subclass like follows, and it works.

class PartTimeEmployee(Employee):
def caculate_wage(self,hours):
self.hours = hours
return hours * 12
print hours * 12

def full_time_wage(self,hours):
    return super(PartTimeEmployee,self).calculate_wage(hours)

There is no need to initialise the subclass, but the biggest problem confused me was the part of accessing the superclass.Now i figure out that the method we called is not 'full_time_wage' but the 'calculate_wage' which is in superclass . The syntax in this section may be not a good one. Which is post as bellow:

class Derived(Base):
def m(self):
return super(Derived, self).m()


#5

If I may offer one suggestion @minionswang: the codeblock button in the editor of these forums (the one with </> on it) will ensure that any code you post will retain its proper indentation and formatting. That way it's easier to read your examples :smile:


#6
Thank you very much for reminding me of this. :smile: