PROGRAM: 15
DATE:22/08/24
Write functions in Python
a. PUSH(N) to add new names (strings) as stack
b. POP(N) to remove names from N as in stack and
c. SHOW(N) to display content of N. Here N is a stack implemented by a list of
names (strings).
Call the above functions using menu driven options in a loop.
SOURCE CODE
N=[]
def PUSH(N):
Name = input('Enter Name : ' )
N.append(Name)
def POP(N):
if len(N)==0:
print('Stack is underflow......')
else:
print('Deleting name is ',N.pop())
def SHOW(N):
if len(N)==0:
print('Stack is underflow.....')
else:
print('Stack is :')
for k in range(-1,-len(N)-1,-1):
print(N[k])
while True:
choice = int(input('1. Push 2. Pop 3. Display 4. Exit : '))
if choice == 1:
PUSH(N)
elif choice==2:
POP(N)
elif choice==3:
SHOW(N)
elif choice==4:
print('Exiting the program.')
break
else:
print('Invalid Choice, Retry....!!!')