14/19 this looks like a job for


#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.hour = 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)

I get the right answer, but one thing I cannot understand is that, how does it calculate with hours * 20 instead of hours * 12? the reason why I don't understand is that in code it seems like Part Time class rate is added rather than class Employee's calculate_wage rate.


#2

Hi @chimansong ,

Because the code that you posted is not formatted, it is difficult for other users to read and debug it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.

This statement uses the super function to call the calculate_wage method of the superclass of the PartTimeEmployee class, which is the Employee class ...

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

When the call from this statement is executed, the argument, self, represents the current instance of the PartTimeEmployee class, which is milton.


#4

I get it now. Thanks


#5

This helped me a bunch.