stk=[] def push(stk,ele): stk.append(ele) def Pop(stk): if len(stk)==0: return "Underflow" else: pop_item=stk.pop() return pop_item def display(stk): if len(stk)==0: return "Underflow" else: top=len(stk)-1 print(stk[top],"<-top") for i in range(top-1,-1,-1): print(stk[i]) while True: print(''' 1. Push 2. Pop 3. Display 4. Exit ''') ch=int(input("Enter your choice:")) if ch==1: e=int(input("Enter the value to push:")) push(stk,e) elif ch==2: i=Pop(stk) if i=='Underflow': print("Underflow! Stack is empty") else: print("Popped Item",i) elif ch==3: display(stk) elif ch==4: break else: print("Invalid Choice") ''' output 1. Push 2. Pop 3. Display 4. Exit Enter your choice:1 Enter the value to push:2 1. Push 2. Pop 3. Display 4. Exit Enter your choice:1 Enter the value to push:3 1. Push 2. Pop 3. Display 4. Exit Enter your choice:3 3 <-top 2 1. Push 2. Pop 3. Display 4. Exit Enter your choice:2 Popped Item 3 1. Push 2. Pop 3. Display 4. Exit Enter your choice:4 '''