Introduction to Classes: Override


#1


Hi, so I've found myself stuck on Part 13 (Override) of Lesson 19

I keep getting the error message "Oops, try again. It looks like your PartTimeEmployee's calculate_wage method doesn't override Employee's calculate_wage method." but when tested, my code prints two separate calculate_wage functions accordingly.


For example, if I set the hours to 7 on an employee and a part time employee, it returns 140.0 and 105.0. However, this doesn't pass the exercise. All tests indicate it's working, so I'm completely at a loss here.


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 * 15.00
        

you = Employee("Miguel")
me = PartTimeEmployee("Bob")
print me.calculate_wage(7) #Prints 105.0
print you.calculate_wage(7) #Prints 140.0


#2

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
         
print PartTimeEmployee.calculate_wage

The last return hours should be * 12 not * 15 which is what you have.
And you don't need to create a 'you' employee yet


#3

Oh, duh, I misread, of course I did. Thank you!


#4

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