Unexpected argument in python

362 Views Asked by At
class Employee:
    def __int__(self, name, salary):
        self.name = name
        self.salary = salary

    def getsalary(self):
        print( self.salary)

rohan = Employee("Rohan","345500")
print(rohan.salary)
print(rohan.name)
#rohan.getsalary()

harry = Employee("Harry", "521000")
print(harry.salary)
print(harry.name)

Could found what is the problem just said that unexpected argument. can any one solve this or help me

output:- The result should be 345500 rohan 521000 harry

1

There are 1 best solutions below

0
On

It is spelling mistake in the __init__ method. When you pass arguments while instantiating an object, it will look for a init method to pass the arguments.

class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

    def getsalary(self):
        print( self.salary)

rohan = Employee("Rohan","345500")
print(rohan.salary)
print(rohan.name)
#rohan.getsalary()

harry = Employee("Harry", "521000")
print(harry.salary)
print(harry.name)