Lesson 14


#1



I have been trying to sort this out since yesterday.
My original ideas did not work but I found a question about the same exercise in the forum and copied the corrected code as below. The result as can be seen is still giving me what seems to be the same error I have been struggling with. Please explain what I have missed.

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


Traceback (most recent call last):
File "python", line 17, in
TypeError: init() should return None, not 'str'


I expected to be able to get no errors and move on to the next exercise.


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 __init__(self, hours):
        self.hours = hours
        return hours * 12.00
    def full_time_wage(self,hours):
        return super(PartTimeEmployee, self).calculate_wage()
milton = PartTimeEmployee("aa")
print milton.full_time_wage(10)


#2

You're missing an argument here

It should be:

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

#3

Thanks, I changed that but now I get:

Traceback (most recent call last):
File "python", line 18, in
File "python", line 14, in init
TypeError: can't multiply sequence by non-int of type 'float'


#4

Ooops! Looking at the error pointed to, this line too:

It should be:

def calculate_wage(self, hours):

So that you now have:

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(hours)
milton = PartTimeEmployee("aa")
print milton.full_time_wage(10)

#5

Thank you thank you so much. That fixed it. I have been learning python for some time but not using classes at all. I started this yesterday and this exercise has really been frustrating me.


#6

More practice will help. :slight_smile:

You're welcome.


#7

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