class and instances: I wrote a program but that gives me an error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dustan
    New Member
    • May 2018
    • 1

    class and instances: I wrote a program but that gives me an error.

    I wrote a simple program but it shows me an error:
    #the program:
    # Python classes

    class Employee:
    raise_amount=1. 04

    def __int__(self, first, last, pay):
    self.__first = first
    self.__last= last
    self.__pay= pay
    self.__email= first+ "." + last + "@company.c om"

    def fullname(self):
    return '{} {}'.format(self .first, self.last)

    def apply_raise(sel f):
    self.pay = int(self.pay * self.raise_amou nt)


    a= Employee('Pawan ' , 'Neu' , '555')
    b= Employee('Sonu' , 'Khatri' , '666')

    print (a.__dict__)
    print(a.fullnam e())
    print(Employee. raise_amount)

    #the error is as follows:
    Traceback (most recent call last):
    File "C:\Users\user\ Desktop\practic e.py", line 19, in <module>
    a= Employee('Pawan ' , 'Neu' , '555')
    TypeError: this constructor takes no arguments
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    To be a member of the class, functions like __init__() have to be indented properly.

    Comment

    Working...