Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to create a python code for employees using the following code but it is coming up with an error "Object () takes no parameters) My objective is to create a program to keep track of employees in an organisation, by allowing the user to add and remove employees from a simple database listing their staff names and number, salaries and update their salaries and read and write all the information into a text file.

So far this is my code:
Python
class Employee:
    """ Employee has name, one staff number, number of years worked, Salary and Holiday"""

def __init__(self, name, StaffNumber, YearsWorked, Salary, HolidayEntitlement):
    self._name=name
    self._StaffNumber=StaffNumber
    self._YearsWorked=[]
    self._Salary=[]
    self._HolidayEntitlement=[]

    def addEmployee(self) :
        text = int(input("Enter Employee's Name"))
        for i in range (text):
            self._name(input("Enter Employee's Name"))

e = Employee("Jean Green", "13026", "7", "£12,890", "42 days")

print ("Employee: ", e._name)
print ("Employee: ", e._StaffNumber)
print ("Employee: ", e._YearsWorked)
print ("Employee: ", e._Salary)
print ("Employee: ", e._HolidayEntitlement)

How do I create it right?
Posted
Updated 11-Dec-14 2:56am
v2
Comments
Richard MacCutchan 11-Dec-14 13:03pm    
Start by explaining where this error occurs. We cannot read your mind.

1 solution

In Python the indentation of your code is critical to the compiler to understand you...In your case def __init__ not indented so this is no part of class - the default creator takes no parameter...
The code should look like this:
Python
class Employee:
    """ Employee has name, one staff number, number of years worked, Salary and Holiday"""
 
    """ Notice the indentation here!!! """
    def __init__(self, name, StaffNumber, YearsWorked, Salary, HolidayEntitlement):
        self._name=name
        self._StaffNumber=StaffNumber
        self._YearsWorked=[]
        self._Salary=[]
        self._HolidayEntitlement=[]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Dec-14 0:09am    
Correct, a 5.
—SA
Kornfeld Eliyahu Peter 12-Dec-14 2:05am    
Thank you...
(Freaking language...)
Sergey Alexandrovich Kryukov 12-Dec-14 2:23am    
Python? To my taste, not bad at all...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900