OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Error in adding an additional argument in __init__ method in sub class [closed]

  • Thread starter Thread starter Mike Rapson
  • Start date Start date
M

Mike Rapson

Guest
I'm getting this error:

Code:
TypeError: employee.__init__() takes 4 positional arguments but 5 were given

Here's the code:

Code:
class employee:

    raiseAmount = 1.04
    numEmpls = 0
    
    def __init__(self, firstName1, lastName, pay):
        self.first = firstName1
        self.last = lastName
        self.pay = pay
        self.email = firstName1 + lastName + "@gmail.com"
    
        employee.numEmpls += 1
    
    def fullName(self):
        return (self.first + self.last)
    
    def applyRaise(self):
        self.pay = int(self.pay * self.raiseAmount)

class developer(employee):

    raiseAmount = 2.0
    
    def __intit__(self, firstName, lastName, pay, progLang):
        
        super().__init__(firstName, lastName, pay) 
        self.lang = progLang

dev1 = developer("jon", "doe", 75000, "python")
dev2 = developer("test", "user", 55000, "c")

I've tried using an alternate way:

Code:
employee.__init__(self, firstName, lastName, pay)

but this too isn't working.
<p>I'm getting this error:</p>
<pre class="lang-none prettyprint-override"><code>TypeError: employee.__init__() takes 4 positional arguments but 5 were given
</code></pre>
<p>Here's the code:</p>
<pre><code>class employee:

raiseAmount = 1.04
numEmpls = 0

def __init__(self, firstName1, lastName, pay):
self.first = firstName1
self.last = lastName
self.pay = pay
self.email = firstName1 + lastName + "@gmail.com"

employee.numEmpls += 1

def fullName(self):
return (self.first + self.last)

def applyRaise(self):
self.pay = int(self.pay * self.raiseAmount)

class developer(employee):

raiseAmount = 2.0

def __intit__(self, firstName, lastName, pay, progLang):

super().__init__(firstName, lastName, pay)
self.lang = progLang

dev1 = developer("jon", "doe", 75000, "python")
dev2 = developer("test", "user", 55000, "c")
</code></pre>
<p>I've tried using an alternate way:</p>
<pre><code>employee.__init__(self, firstName, lastName, pay)
</code></pre>
<p>but this too isn't working.</p>
 
Top