This looks like a job for


#1



https://www.codecademy.com/courses/python-intermediate-en-WL8e4/2/4?curriculum_id=4f89dab3d788890003000096


Oops, try again. milton.full_time_wage(0) caused the following exception: calculate_wage() takes exactly 2 arguments (1 given)


Don't derived classes have access to functions of the superclass already? (Because they are derived?)
Why do we need a separate super function?


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):
      return super(PartTimeEmployee,self).calculate_wage()

milton=PartTimeEmployee("Milton John")
print milton.calculate_wage(10)


#2

return super(PartTimeEmployee,self).calculate_wage()

In this line, you forgot to pass argument to calculate_wage() .


#3

Thank you @greentreemee. I have a couple of questions:
1.Don't derived classes have access to functions of the superclass already? (Because they are derived?)
Why do we need a separate super function?

2.Passing self as an argument is a little confusing. Could you please elaborate on that?


#4

1.Don't derived classes have access to functions of the superclass already? (Because they are derived?)
Why do we need a separate super function?

updated**

Why use self?
self helps you to add methods and attributes to your class.
Think it as like your school / College ID...without it you can't go and take classes.
You can't use school/college services or functionality(teaching) they provide.
By your id they come to know that you're a part of school/college.

do reply if it makes your doubt clear or not!


#5

For the first question:

Please let me know if I have understood it correctly.
There is a need to use super function because calculate_wage has been overridden in class 'PartTimeEmployee'. Because we need the original function, we use 'super'.

Therefore,'super' is used in cases where one particular method has to be both overridden and retained as defined in the parent class.

For the second question:

I still do not understand why self is passed as the second argument in the below line.
return super(PartTimeEmployee,self).calculate_wage()

In the previous lines, wherever self is used, it is passed as the first argument.


#6

First one..

You're there.

Second one.

Im linking two links..

The self variable in python explained

Creator of Python himself on self

I was going to create a post about : why we actually needed OOP and what terminologies
used inside it (I found it will be a big post..so I abandoned the thought..maybe someday I will make a post about it explaining all about OOP)

For the time being these links are sufficient.
If you still unable to get the idea, do reply!:slight_smile:


#7

Thank you for links!


#8

You're welcome! :slight_smile:


#9

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