[go: up one dir, main page]

0% found this document useful (0 votes)
34 views1 page

Program 15

Uploaded by

LAWANIYA SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Program 15

Uploaded by

LAWANIYA SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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....!!!')

You might also like