01.
09 5:05 PM
# Payroll Management System
# Initialize an empty list to store employee records
employees = []
# Function to add an employee
def add_employee():
print("Add Employee:")
serial_no = len(employees) + 1 # Automatically assign serial number
name = input("Enter Employee Name: ")
post = input("Enter Employee Post: ")
age = int(input("Enter Employee Age: "))
salary = float(input("Enter Employee Salary: "))
employees.append({'serial_no': serial_no, 'name': name, 'post': post, 'age':
age, 'salary': salary})
print("Employee added successfully!\n")
# Function to display all employees
def display_all():
print("Displaying All Employee Records:")
if not employees:
print("No records found!\n")
else:
for emp in employees:
print(f"Serial No: {emp['serial_no']}, Name: {emp['name']}, Post:
{emp['post']}, Age: {emp['age']}, Salary: {emp['salary']}")
print()
# Function to display employees by name
def display_by_name():
name = input("Enter the name to search: ")
found = False
for emp in employees:
if emp['name'].lower() == name.lower():
print(f"Serial No: {emp['serial_no']}, Name: {emp['name']}, Post:
{emp['post']}, Age: {emp['age']}, Salary: {emp['salary']}")
found = True
if not found:
print("No record found with the given name!\n")
# Function to display employees by post
def display_by_post():
post = input("Enter the post to search: ")
found = False
for emp in employees:
if emp['post'].lower() == post.lower():
print(f"Serial No: {emp['serial_no']}, Name: {emp['name']}, Post:
{emp['post']}, Age: {emp['age']}, Salary: {emp['salary']}")
found = True
if not found:
print("No record found with the given post!\n")
# Function to delete an employee record
def delete_record():
serial_no = int(input("Enter Serial No of the employee to delete: "))
for emp in employees:
if emp['serial_no'] == serial_no:
employees.remove(emp)
print("Employee record deleted successfully!\n")
return
print("No record found with the given Serial No!\n")
# Function to update an employee record
def update_record():
serial_no = int(input("Enter Serial No of the employee to update: "))
for emp in employees:
if emp['serial_no'] == serial_no:
print("Current Record:", emp)
emp['name'] = input("Enter New Name (Leave blank to keep current): ")
or emp['name']
emp['post'] = input("Enter New Post (Leave blank to keep current): ")
or emp['post']
emp['age'] = int(input("Enter New Age (Leave blank to keep current): ")
or emp['age'])
emp['salary'] = float(input("Enter New Salary (Leave blank to keep
current): ") or emp['salary'])
print("Employee record updated successfully!\n")
return
print("No record found with the given Serial No!\n")
# Main Program Menu
while True:
print("Payroll Management System")
print("1. Add Employee")
print("2. Display All Records")
print("3. Display by Name")
print("4. Display by Post")
print("5. Delete a Record")
print("6. Update a Record")
print("7. Exit")
choice = input("Enter your choice: ")
if choice == '1':
add_employee()
elif choice == '2':
display_all()
elif choice == '3':
display_by_name()
elif choice == '4':
display_by_post()
elif choice == '5':
delete_record()
elif choice == '6':
update_record()
elif choice == '7':
print("Exiting Payroll Management System. Goodbye!")
break
else:
print("Invalid choice! Please try again.\n")