stack=[]
def PUSH():
val=input('Enter an integer: ')
num=int(val)
stack.append(num)
def POP():
if len(stack)==0:
print('Stack is Empty.')
else:
deletedelement=stack.pop()
print(deletedelement, ' is deleted.')
def Display():
N=len(stack)
if N!=0:
for i in range(N-1,-1,-1):
print(stack[i],'->')
else:
print('Stack is Empty.')
opt='Y'
while opt=='y' or opt=='Y':
print('1.PUSH')
print('2.POP')
print('3.Display')
choice=input('Enter the option: ')
if choice=='1':
PUSH()
elif choice=='2':
POP()
elif choice=='3':
Display()
opt=input('Do you want to continue: ')
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter