CBSE BOARD XII, asked by ananya191102, 7 months ago

2. Write a menu driven program to perform following stack operations in python
I. Push student roll no Into the stack
Ii.Pop the roll no
III.Peek rollno
IV.Display the stack​

Answers

Answered by rajeshsinghkolkata12
2

Answer:

pop the roll on .

Explanation:

please mark me brainliest

Answered by sangeeta7paulsl
0

Answer:

Explanation:

def isEmpty(stk):

   if stk == []:

       return True

   else:

       return False

def add(stk,item):

   stk.append(item)

   top = len(stk)-1

   

def remove(stk):

   if(stk==[]):

       print("Stack empty;UNderflow")

   else:

       print("Deleted student is :",stk.pop())

   

def display(stk):

   if isEmpty(stk):

       print("Stack empty ")

   else :

       top = len(stk)-1

       print(stk[top],"<-top")

       for a in range(top-1,-1,-1):

           print(stk[a])

           

stack=[]

top = None

while True:

   print("STACK OPERATION:")

   print("1.ADD student")

   print("2.Display stack")

   print("3.Remove student")

   print("4.Exit")

   ch = int(input("Enter your choice(1-4):"))

   if ch==1:

       rno = int(input("Enter Roll no to be inserted :"))

       sname = input("Enter Student name to be inserted :")

       item = [rno,sname]

       add(stack,item)

       input()

   elif ch==2:

       display(stack)

       input()

   elif ch==3:

       remove(stack)

       input()    

   elif ch==4:

       break

   else:

       print("Invalid choice ")

       input()

   

           

#spj3

Similar questions