Implementation of stack in Python using lists.
Tue Mar 29 2022 16:06:40 GMT+0000 (Coordinated Universal Time)
Saved by
@ProjecRexa
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: ')
content_copyCOPY
Comments