#Write a python menu driven code to perform PUSH,POP and DISPLAY operations
def IsEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,item):
[Link](item)
def Pop(stk):
if IsEmpty(stk):
return 'Underflow'
else:
item=[Link]()
return item
def Display(stk):
if IsEmpty(stk):
print('Empty Stack')
else:
top=len(stk)-1
print(stk[top],'<-- Top')
for i in range(top-1,-1,-1):
print(i)
stack=[]
while True:
print('STACK OPERATIONS')
print('1. Push')
print('2. Pop')
print('3. Display')
print('4. Exit')
ch=int(input('Enter your choice:'))
if ch==1:
item=int(input('Enter item:'))
Push(stack,item)
elif ch==2:
item=Pop(stack)
if item=='Underflow':
print('Underflow')
else:
print('Popped item is',item)
elif ch==3:
Display(stack)
elif ch==4:
break
else:
print('Invalid choice')
OUTPUT: