Python|Queues|Maintaining student details

Maintaining student details

like roll, name and per, using Queues (Using Functions)

Operations

Creation of empty queue

employee=[]

Addition of element

def add_element():
          roll=input(“Enter roll “)
          name=input(“Enter name “)
          per=input(“Enter per “)
          std=(roll,name,per)
          student.append(std)

Deletion of element

if(student==[]):
         print(“Underflow / student Queue in empty”)
else:
         roll,name,per=student.pop(0)
         print(“poped element is “)
         print(“roll “,roll,” name “,name,” per “,per)

To check Queue is empty or not

if(student==[]):
        print(“No Student /Queue is empty”)
else:
         print(“Queue is not empty”)

Traversal operation

def traverse():
         if not (student==[]):
                n=len(student)
                for i in range(0,n):
                      print(student[i])
        else:
               print(“Empty , No student to display”)

#queue implementation (using functions)
 #program to create a queue of student(roll,name,per).
"""
 add student
 delete student
 traverse / display all student
"""
student=[]
def add_element():
         roll=input("Enter roll  ")
         name=input("Enter name ")
         per=input("Enter per ")
         std=(roll,name,per)
         student.append(std)
def del_element():
        if(student==[]):
                print("Underflow / student Queue in empty")
        else:
                roll,name,per=student.pop(0)
                print("poped element is ")
                print("roll ",roll," name ",name," per ",per)
def traverse():
        if not (student==[]):
                n=len(student)
                for i in range(0,n):
                        print(student[i])
        else:
                print("Empty , No student to display")
while True:
        print("1. Add element");
        print("2. Delete element");
        print("3. Traversal")
        print("4. Exit")
        ch=int(input("Enter your choice "))
        if(ch==1):
                add_element()
        elif(ch==2):
                del_element();
        elif(ch==3):
                traverse()
        elif(ch==4):
                print("End")
                break
        else:
                print("Invalid choice")
                

Visitor Counter

0056739