This Looks Like a Job For


#1

Em help please. In theory this code should not work or accepted but it does work and was accepted.. Line 24, "return hours *20", do we need it? The impression I had was that, for this exercise, because line 8 already has " return hours * 20, hence line 24 is not needed. I had lots and lots of trials and improvement to get it accepted. hmmm
180.0
200
None
PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>


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):
        self.hours=hours
        return super(PartTimeEmployee,self).calculate_wage(self,hours)
    #def full_time_wage(self,hours): a repeat of lines 15 to 17
        #self.hours = hours
        #return super(PartTimeEmployee,self).calculate_wage(self,hours)
class Full_Time_Employee(PartTimeEmployee):
    def full_time_wage(self,hours):
        self.hours = hours
        return hours*20
John  = PartTimeEmployee("John")
print John.calculate_wage(15)#hours =15
milton = Full_Time_Employee("milton")
print milton.full_time_wage(10)#hours = 10
Replace this line with your code.


#2

Hi @becon12,

You did extra work for this exercise by creating a Full_Time_Employee class. The Employee class already represents full time employees.

Your Full_Time_Employee class doesn't really add any functionality to the program, because it only defines a full_time_wage method, which is already defined in the parent PartTimeEmployee class. It just needs to be revised to correct a mistake.

The actual problem is in this line within that method ...

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

The entire method should be ...

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

Notice that in the above, the only explicit argument to the calculate_wage method is now self.hours. The object on which that method being called is super(PartTimeEmployee,self), which is the current instance of PartTimeEmployee, acting as an Employee, which is the class that represents a full time employee.

After revising that full_time_wage method, you can discard the Full_Time_Employee class, and then reconfigure milton as an Employee, instead of a Full_Time_Employee, as follows ...

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

With those changes, your code should continue to work, and also conform to the intentions of the exercise. If you encounter any problems, post your revised code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.