PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  1. Python For Data Analytics
  2. 1.Python
  3. 3.Python Projects

Employee Management System

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 -

  1. 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.

  2. 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.

  3. Delete Employee In this, An employee can be deleted using the employee ID.

  4. List Employee In this, List of all the employees will be shown to the user in tabular format.

  5. 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:

----Employee Management System-----

  1. Add Employee

  2. Update Employee

  3. Delete Employee

  4. List Employees

  5. Exit

Enter your choice: 1

Enter Employee Details:

ID: 101 Name: Mohan Age: 20 Gender: Male Position: Manager Salary: 100000 Employee added successfully.

Enter the Employee ID

ID: 101 Which Information you want to update :

  1. Name

  2. Age

  3. Gender

  4. Position

  5. Salary Enter Your choice : 3 Gender : Male Enter 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 add
employees = []

# Add Employee
def add_employee():
    flag = True # for checking the uniqueness of the ID of the employee
    print("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 not
    if not employees:
        flag = True
    else:
        for emp in employees:
            if id  == emp['id']:
                flag = False
                break
    if 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 Employee
def update_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 details
    for employee in employees:
        if employee['id'] == id: #condition for finding the employee
            print('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 update
            if ch == 1:
                #showing the current value of column name
                print('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 loop
            return
    #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 Employee
def delete_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 Employees
def list_employees():
    if len(employees) == 0:
        print("No employees found.")
        return
    #Printing in tabular format
    print("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 Loop
while True:
    #Through this loop the execution of the program starts
    #and this is the user view
    print()
    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!!')
        break
    else:
        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.

Previous3.Python ProjectsNextHamming distance

Last updated 2 years ago