Python Linked List Maintain Employee details

Maintain Employee details

Maintain Employee details like empno, name, and sal.

Operations

1. Add at start

2. Add at end

3. Add at a position

4. Display All

5. Delete 1st element

6. Delete last element

7. Delete by position

8. Delete all elements

9. search record by empno

10. Search record by name

#list 
#to maintain employee details like empno,name and sal
#Create a Empty list
import os

employee=[]
#add aty start
def addatstart():
    empno=input("Enter empno no ")
    name=input("Enter name no ")
    sal=input("Enter sal no ")
    emp=(empno,name,sal)
    if(len(employee)==0):
        employee.append(emp)
    else:
        employee.insert(0,emp)


def addatend():
    empno=input("Enter empno no ")
    name=input("Enter name no ")
    sal=input("Enter sal no ")
    emp=(empno,name,sal)
    employee.append(emp)


def addatposition():
    empno=input("Enter empno no ")
    name=input("Enter name no ")
    sal=input("Enter sal no ")
    emp=(empno,name,sal)
    pos=int(input("Enter the position "))
    employee.insert(pos-1,emp)


def display_all():
    if(employee==[]):
        print("List is empty")
    else:
        print("List is 1st method\n")
        for i in employee:
            print(i)
        print("\nList is 2nd method\n")
        i=0
        while(i<len(employee)):
            print("empno ",employee[i][0],employee[i][1],employee[i][2])
            i=i+1


def del_first():
    if(employee==[]):
        print("List is empty")
    else:
        print("Deleted 1st element is ",employee[0])
        employee.pop(0)


def del_last():
    if(employee==[]):
        print("List is empty")
    else:
        print("Deleted Last element is ",employee.pop())


def del_at_position():
    pos=int(input("Enter the position "))
    if not (pos<=0 or pos>len(employee)):
        if(employee==[]):
            print("List is empty")
        else:
            print("Deleted element is ",employee.pop(pos-1))
    else:
        print("Invalid position")


def delete_all():
    employee.clear()


def search_empno():
    z=0
    r=input("Enter empno to search ")
    if(employee==[]):
        print("employee List is empty")
    else:
        i=0
        while(i<len(employee)):
            if(employee[i][0]==r):
                print("Record Found , Details are")
                z=1
                print("empno ",employee[i][0],employee[i][1],employee[i][2])
            i=i+1
        if z==0:
            print("Record with empno no ",r," is not present")

    
def search_name():
    z=0
    n=input("Enter Name to search ")
    if(employee==[]):
        print("employee List is empty")
    else:
        i=0
        while(i<len(employee)):
            if(employee[i][1]==n):
                print("Record Found , Details are")
                z=1
                print("empno ",employee[i][0],employee[i][1],employee[i][2])
            i=i+1
        if z==0:
            print("Record with Name ",n," is not present")

def main():

    while True:
        os.system("cls")
        print("\n\n\n1. Add at start ")
        print("2. Add at end ")
        print("3. Add at a position ")
        print("4. Display All")
        print("5. Delete 1st element ")
        print("6. Delete last element ")
        print("7. Delete by position ")
        print("8. Delete all elements ")
        print("9. search By empno ")
        print("10. search By Name")
    
        print("0. Exit")
        ch=int(input("Enter your choice "))
        if(ch==1):
            addatstart()
        elif(ch==2):
            addatend()
        elif(ch==3):
            addatposition()
        elif(ch==4):
            display_all()
        elif(ch==5):
            del_first()
        elif(ch==6):
            del_last()
        elif(ch==7):
            del_at_position()
        elif(ch==8):
            delete_all()
        elif(ch==9):
            search_empno()
        elif(ch==10):
            search_name()
        elif(ch==0):
            break
        else:
            print("Invalid choice ")
        input("Press Enter to cont ...")


if __name__ == "__main__":
    main()

Visitor Counter

0161220