Employee Data Management

mail@pastecode.io avatar
unknown
plain_text
5 months ago
5.5 kB
3
Indexable
# Important Library
from print_color import print

# Employee List
employees = [
    {
        "id": 1,
        "name": "Bob",
        "age": 15,
        "department": "Software Engineer",
        "salary": 15000
    },

    {
        "id": 2,
        "name": "Lam",
        "age": 24,
        "department": "Software Engineer",
        "salary": 50200
    },

    {
        "id": 3,  
        "name": "John Doe",
        "age": 30,
        "department": "Cybersecurity",
        "salary": 10400
    },

    {
        "id": 4,  
        "name": "Jane Doe",
        "age": 65,
        "department": "Cybersecurity",
        "salary": 70800
    }
]


# Menu Screen
while True:
    print("What would you like to do? \n\n",  tag='EMPLOYEE DATABASE', tag_color='yellow', color='white', format='bold')
    print("Add Employee \n", tag='1', tag_color='black', color='grey', format='bold')
    print("Remove Employee \n", tag='2', tag_color='black', color='grey', format='bold')
    print("Find Employee \n", tag='3', tag_color='black', color='grey', format='bold')
    print("Display Options \n", tag='4', tag_color='black', color='grey', format='bold')
    print("Exit \n", tag='5', tag_color='black', color='grey', format='bold')

    choice = input("")
    

# Add employee data
    if choice == "1":
        id = int(input("Enter employee's ID: "))
        name = str(input("Enter employee's name: "))
        age = int(input("Enter employee's age: "))
        department = str(input("Enter employee's department: "))
        salary = int(input("Enter employee's salary: "))

        employee = {
                "id": id,
                "name": name,
                "age": age,
                "department": department,
                "salary": salary
        }

        employees.append(employee)
        print(f"Employees {name}'s data was added \n", tag = 'success', tag_color = 'green', color = 'black', format='bold')


# Remove employee data
    elif choice == "2":
        id_to_del = int(input("Enter ID to delete employee's data: "))
        found = False
        for employee in employees:
             if employee["id"] == id_to_del:
                  employees.remove(employee)
                  found = True
                  print(f"Employee ID:{id_to_del}'s data was removed\n", tag = 'success', tag_color = 'green', color = 'black', format='bold')
                  break
             
        if not found:
             print(f"Employee ID: {id_to_del} does not exist\n", tag = 'failure', tag_color = 'red', color = 'magenta', format='bold')


# Find employee by ID
    elif choice == "3":
        id_to_find = int(input("Enter employee's ID: "))
        found = False
        for employee in employees:
            if employee["id"] == id_to_find:
                found = True
                print(f"{employee["name"]} / Age: {employee["age"]} / Department: {employee["department"]} / Salary: {employee["salary"]}\n", color = 'grey', format = 'bold')
                break

        if not found: 
            print(f"Employee ID: {id_to_find} does not exist\n", tag = 'failure', tag_color = 'red', color = 'magenta', format='bold')


# Display options
    elif choice == "4":
        print("What would you like to do? \n\n",  tag='DISPLAY OPTIONS', tag_color='cyan', color='white', format='bold')

        print("Display All Employees \n", tag='1', tag_color='black', color='grey', format='bold')
        print("Display Employees Above Certain Age \n", tag='2', tag_color='black', color='grey', format='bold')
        print("Display Highest Salary \n", tag='3', tag_color='black', color='grey', format='bold')
        print("Display Department Avg Salary \n", tag='4', tag_color='black', color='grey', format='bold')

        display_choice = input("")


        # Display All Employees
        if display_choice == "1":
            for employee in employees:
                print(f"{employee['id']} / Name: {employee['name']} / Age: {employee['age']} / Department: {employee['department']} / Salary: {employee['salary']}\n", tag = 'ID:', tag_color = 'green', color = 'grey', format = 'bold')


        # Display Employees Above Certain Age
        if display_choice == "2":
            age_minimum = int(input("Enter age minimum: "))
            found = False

            for employee in employees:
                if employee["age"] >= age_minimum:
                    found = True
                    print(f"{employee['id']} / Name: {employee['name']} / Age: {employee['age']} / Department: {employee['department']} / Salary: {employee['salary']}\n", tag = 'ID:', tag_color = 'green', color = 'grey', format = 'bold')
    
            if not found:
                print("There are no employees above this age")

        
        # Display Highest Salary
        if display_choice == "3":
            top_salary = employees[0]
            for employee in employees:
                if employee["salary"] > top_salary["salary"]:
                    top_salary = employee

            print(f"{employee['id']} / Name: {employee['name']} / Age: {employee['age']} / Department: {employee['department']} / Salary: {employee['salary']}\n", tag = 'ID:', tag_color = 'green', color = 'grey', format = 'bold')

        
        # Display Department Avg Salary (Unfinished)
        

# Exit
    elif choice == "5":
        print("Thank you, have a good day", color = 'white', format = 'bold')
        break


# Error 
    else:
        print("Error detected \n", tag = 'failure', tag_color = 'red', color = 'magenta', format='bold')
Leave a Comment