forked from Ayu-hack/Hacktoberfest2024-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployeemanagement.py
100 lines (81 loc) · 3.65 KB
/
employeemanagement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#Employee Management System
class Employee:
def __init__(self, emp_id, name, position, department, salary):
self.emp_id = emp_id
self.name = name
self.position = position
self.department = department
self.salary = salary
def __str__(self):
return f"ID: {self.emp_id}, Name: {self.name}, Position: {self.position}, Department: {self.department}, Salary: {self.salary}"
class EmployeeManagementSystem:
def __init__(self):
self.employees = []
def add_employee(self, emp_id, name, position, department, salary):
new_employee = Employee(emp_id, name, position, department, salary)
self.employees.append(new_employee)
print(f"Employee {name} added successfully.")
def view_employees(self):
for employee in self.employees:
print(employee)
def update_employee(self, emp_id, name=None, position=None, department=None, salary=None):
for employee in self.employees:
if employee.emp_id == emp_id:
if name:
employee.name = name
if position:
employee.position = position
if department:
employee.department = department
if salary:
employee.salary = salary
print(f"Employee ID {emp_id} updated successfully.")
return
print("Employee not found.")
def delete_employee(self, emp_id):
for employee in self.employees:
if employee.emp_id == emp_id:
self.employees.remove(employee)
print(f"Employee ID {emp_id} deleted successfully.")
return
print("Employee not found.")
def main():
ems = EmployeeManagementSystem()
while True:
print("\nEmployee Management System")
print("1. Add Employee")
print("2. View Employees")
print("3. Update Employee")
print("4. Delete Employee")
print("5. Exit")
choice = input("Choose an option: ")
if choice == '1':
emp_id = input("Enter Employee ID: ")
name = input("Enter Name: ")
position = input("Enter Position: ")
department = input("Enter Department: ")
salary = float(input("Enter Salary: "))
ems.add_employee(emp_id, name, position, department, salary)
elif choice == '2':
ems.view_employees()
elif choice == '3':
emp_id = input("Enter Employee ID to update: ")
name = input("Enter new Name (leave blank to retain current): ")
position = input("Enter new Position (leave blank to retain current): ")
department = input("Enter new Department (leave blank to retain current): ")
salary = input("Enter new Salary (leave blank to retain current): ")
salary = float(salary) if salary else None
ems.update_employee(emp_id, name if name else None,
position if position else None,
department if department else None,
salary)
elif choice == '4':
emp_id = input("Enter Employee ID to delete: ")
ems.delete_employee(emp_id)
elif choice == '5':
print("Exiting the Employee Management System.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()