14/18 This works, this exercise has a bad syntax example.. please change


#1

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 calculate_wage(self, hours):
self.hours = hours
return hours * 12.00
def full_time_wage(self, hours):
return super(PartTimeEmployee, self).calculate_wage(hours)

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


#3

this one works for me:

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 calculate_wage(self, hours):
        self.hours = hours
        return hours * 12.00
        
    def full_time_wage(self, hours):
            
        return super(PartTimeEmployee, self).calculate_wage(hours) #1 arg idk why
        
milton = PartTimeEmployee("milton")

print milton.full_time_wage(10)

#4

The calculate_wage function in the full_time_wage function only takes one parameter because Python already knows who is calling the function so it does not need the self parameter.


#5

Can you further explain this? This sort of makes sense but I had some trouble with this one. Thanks!


#6

Ok, so I'll try and break down this line a bit

The super() function is used to call a function in the parent class (in this case, Employee is the parent class). The calculate_wage method does not need a 'self' parameter because whatever calls the method is assigned to the 'self' parameter. So whatever PartTimeEmployee calls the calculate_wage becomes the 'self' so self.hours is equal to that particular's PartTimeEmployee's hours. That's why you need to pass self in the super method!

Object Orientated Programing is pretty tricky and takes a while to get the hang of, so keep coding and the lightbulb moments will happen!

And here's more reading:
https://docs.python.org/2/library/functions.html#super