This Looks Like a Job For… Help please!


#1

Why cannot this code pass?
I changed the last code into: print milton.full_time_wage(4)
Then changed to return super(PartTimeEmployee, self).calculate_wage(hours)
Then I can pass.
But I don't understand why.
The following is my original 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

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)

milton=PartTimeEmployee("Milton")
print full_time_wage(milton,4)

#2

full_time_wage only takes in one input (AKA parameter). You seem to have tried to put in two here:

Hours should be 10 and not 4 fyi (from instructions).


#3

Thank you. But I get confused about the "self". When do we need it and when do we only need other parameters, eg. hours?

It seems here that the full_time_wage function only needs hours.
But a similar function calculate_wage would require a "self" in its parameter.
Why is it this case?


#4

print full_time_wage(milton,4)

Since datfatat already addressed the arguments, to call a class on a variable we use the format:

print variable.class(arg)

Here is more on classes:
https://docs.python.org/2/tutorial/classes.html


#5

It is very helpful. Thank you very much.


#6

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