An Employee Management System is a software application used by organizations to manage their employee data. It helps to keep track of employee information such as their personal details, job position, salary, and other related data. It is designed to streamline HR operations and automate administrative tasks related to employees.
You have to build a basic employee management system using python which should perform the following functions -
Add Employee
In this, employee details can be added. The details will include the ID,Name, Age, Gender, Job Position and salary. Also a check will be applied to ensure uniqueness of the Employee ID.
Update Employee
In this, employee detail can be updated using employee id
Also a submenu will be provided to the user to choose for which information he wants to update. such as Name, Gender, etc. ID for the employee will not be updated once defined it will remain same for the concerned employee.
Delete Employee
In this, An employee can be deleted using the employee ID.
List Employee
In this, List of all the employees will be shown to the user in tabular format.
Exit
Now at the end your program will ask the user to exit from the program.
These options will be provided to the user each and every time the user performs an operation successfully such as addition or deletion of the employee.
This program doesn't to be a GUI application, it will be simple console based and will not involve the use of database and database applications such as MY SQL, SQL Server, etc.
Here are some Examples:
Salary
Enter Your choice : 3
Gender : MaleEnter the Gender : Female
Employee Details updated Successfully
Enter Employee ID:
ID: 101
Employee deleted successfully.
ID
Name
Age
Gender
Position
Salary
101
Mohan
20
Male
Manager
100000
102
Madan
20
Male
Asst. Manager
80000
103
Damodar
22
Male
Clerk
20000
Program Exited!!
You can further Improve your project on your own by adding some more functionalities and features.
Solution
# Employee Management System#Globally a list has been created for employees to addemployees = []# Add Employeedefadd_employee(): flag =True# for checking the uniqueness of the ID of the employeeprint("Enter Employee Details:")id=int(input("ID: ")) name =input("Name: ") age =int(input("Age: ")) gender =input("Gender: ") position =input("Position: ") salary =float(input("Salary: "))#Now Checking whether the ID provided by the user already exists or notifnot employees: flag =Trueelse:for emp in employees:ifid== emp['id']: flag =Falsebreakif flag ==True:#If ID is unique then add the details#Dictionary of employee with his details as key value pair has been added employee ={'id':id,'name': name,'age': age,'gender': gender,'position': position,'salary': salary}#Now this detail is added in that globally declared list. employees.append(employee)print("Employee added successfully.")else:print('ID already exists!!')# Update Employeedefupdate_employee():#Taking ID from the user on which update is to be performed.print("Enter Employee ID:")id=int(input("ID: "))#Loop for finding the employee with the ID provided to update detailsfor employee in employees:if employee['id']==id:#condition for finding the employeeprint('Which Information you want to update : ')print('1. Name')print('2. Age')print('3. Gender')print('4. Position')print('5. Salary') ch =int(input('Enter Your choice : '))#Now checking for which information has to be updated#On deciding, first line will show the current value of that column#Second, new value will be asked from the user to updateif ch ==1:#showing the current value of column nameprint('Name : ', employee['name'])#Taking the new value from the user to update employee['name']=input('Enter the new name :')elif ch ==2:print('Age : ', employee['age']) employee['age']=input('Enter the age :')elif ch ==3:print('Gender :', employee['gender']) employee['gender']=input('Enter the Gender : ')elif ch ==4:print('Name : ', employee['position']) employee['position']=input('Enter the position :')elif ch ==5:print('Salary : ', employee['salary']) employee['salary']=input('Enter the salary :')print('Employee Details updated Successfully')print()#On successfully adding the employee#return statement will return the control the while loop of options from#add function to the while loopreturn#If employee with the ID provided is not found then no return#statement will be executed and thus employee not found message#Will be displayed to the user as written below.print("Employee not found.")# Delete Employeedefdelete_employee():print("Enter Employee ID:")id=int(input("ID: "))for employee in employees:if employee['id']==id:#On finding the employee with the concerned details#Employee is removed from list employees using remove function of list employees.remove(employee)print("Employee deleted successfully.")return#here same logic for return is applied as explained in above add function.print("Employee not found.")# List Employeesdeflist_employees():iflen(employees)==0:print("No employees found.")return#Printing in tabular formatprint("ID\tName\tAge\tGender\tPosition\tSalary")print()for employee in employees:print(f"{employee['id']}\t{employee['name']}\t{employee['age']}\t{employee['gender']}\\t{employee['position']}\t{employee['salary']}")# Main LoopwhileTrue:#Through this loop the execution of the program starts#and this is the user viewprint()print("----Employee Management System-----")print("1. Add Employee")print("2. Update Employee")print("3. Delete Employee")print("4. List Employees")print("5. Exit") choice =int(input("Enter your choice: "))if choice ==1:add_employee()elif choice ==2:update_employee()elif choice ==3:delete_employee()elif choice ==4:list_employees()elif choice ==5:print('Program Exited!!')breakelse:print("Invalid choice. Please try again.")
Code Explanation
The above code starts from the while loop and that is the user view means first time the user interacts with the options provided there.
On choosing the options user is asked for the necessary details to be added.
A list employees = [] has been declared globally to add employees with their details in the form of dictionary. It is declared globally so that it is available throughout the program.
add_employee() function is defined to add the employee which takes the employee id from the user and checks whether any user with the ID provided exists or not. If yes then a message is displayed that user already exist otherwise the details are added in the form of dictionary in the list employees[] declared globally
update_employee() function updates the employee details by taking the user id and finds the employee with that employee id and displays a submenu to the user asking which detail user want to update. Each option shows its old value and asks for the new value from the user.
delete_employee() function deleted the employee on the basis of employee ID.
list_employees()function displays list of all the employees in the tabular format.
Inside these functions on few places return is used to return the control to the while loop if the employee is found and the necessary operation is performed successfully. If the employee is not found then this return statement will not be executed as the control will not come inside the if block then a message Employee not found is displayed to the user.