Override! Method doesnt print output?


#1



I've cleared the exercise. What I want to understand is this: Why can't the print function within the method work? Below is my code. I cant make the total wage come out automatically from the method.

In other words, how do I make Billy.calculate_wage(5) print 60.0 in the output?


Replace this line with your 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 calculate_wage(self, hours):
        self.hours = hours
        return hours* 12.00
        print hours* 12.00
Billy = PartTimeEmployee("Billy") #Remember to add the right number of arguments. For example, this method demands 2 which are self and name. So put the name!!# 
Billy.calculate_wage(5)


#2

a function (and also a method) ends when a return keyword is reached. So your print is never reached, You could swap print and return around, but a better solution would be to print what the function returns by adding a print when calling the method:

print Billy.calculate_wage(5)

#3

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