100% found this document useful (1 vote)
415 views2 pages

Write A Menu Based Program To Add

The document defines functions to add and remove records to a stack data structure implemented as a list in Python. The push() function adds a hostel record with number, students, and rooms to the list. The pop() function removes and prints the last added record if the list is not empty. A menu program uses these functions to add, delete, and display hostel records from the stack.

Uploaded by

Mauryav Ansh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (1 vote)
415 views2 pages

Write A Menu Based Program To Add

The document defines functions to add and remove records to a stack data structure implemented as a list in Python. The push() function adds a hostel record with number, students, and rooms to the list. The pop() function removes and prints the last added record if the list is not empty. A menu program uses these functions to add, delete, and display hostel records from the stack.

Uploaded by

Mauryav Ansh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

Write push(rollno) and pop() method in python:

    push(rollno) --add roll number in Stack


    pop() --- remove roll number from Stack.

MyStack=[]

def Push(rollno):     
MyStack.append(rollno)

def Pop(MyStack):
 if len(MyStack) > 0:   
MyStack.pop()
else:   
print("Stack is empty.")

Write a menu based program to add, delete and display the record of hostel
using list as stack data structure in python. Record of hostel contains the
fields : Hostel number, Total Students and Total Rooms.

host=[ ]
ch='y'

def push(host):
hn=int(input("Enter hostel number"))
ts=int(input("Enter Total students"))
tr=int(input("Enter total rooms"))
temp=[hn,ts,tr]
host.append(temp)

def pop(host):
if(host==[]):
print("No Record")
else:
print("Deleted Record is :",host.pop())

def display(host):
l=len(host)
print("Hostel Number\tTotal Students\tTotal Rooms")
for i in range(l-1,-1,-1):
print(host[i][0],"\t\t",host[i][1],"\t\t",host[i][2])
while(ch=='y' or ch=='Y'):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
push(host)
elif(op==2):
pop(host)
elif(op==3):
display(host)
elif(op==4):
break
ch=input("Do you want to enter more(Y/N)")

You might also like