Question about "This Looks Like a Job For..."


#1


Question about "This Looks Like a Job For..."


https://www.codecademy.com/courses/python-intermediate-en-WL8e4/2/4


I get no errors in the console neither in PyCharm, but I there is the error on UI validator which blocks me from moving to the next lesson.
The error is "Oops, try again. milton.full_time_wage(0) returned 20.0 instead of the correct value: 0"


No errors or reasonable explanation of what is wrong with my 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
        
    def full_time_wage(self, hour):
        return super(PartTimeEmployee, self).calculate_wage(hours)
        
milton = PartTimeEmployee(Employee)
hours=1
print milton.full_time_wage(hours)

https://www.codecademy.com/courses/python-intermediate-en-WL8e4/2/4


#2

Hi @kaliuzhnyi.o,

This is your full_time_wage method for PartTimeEmployee, of which milton is an instance ...

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

Note that you have a parameter named hour, but you use a variable named hours to perform the calculation of the result.

Then you assign 1 to a global variable named hours here ...

hours=1

Codecademy caches that variable in memory, and as a result all calculations for a PartTimeEmployee's full_time_wage method pass that value of 1 to Employee's calculate_wage method and produce a result of 20.0.

The remedy for the problem is to revise the method header as follows, to name the parameter hours instead of hour...

    def full_time_wage(self, hours):

Then, this line will access the parameter, hours, instead of the global variable, hours ...

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

You will not need this line ...

hours=1

#3

Thanks a lot for assistance : )


#4