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

STACK

The document outlines a menu-driven program for managing a list of products, allowing users to add products, push products with prices below 500 into a stack, and pop all elements from the stack. It includes functions for product input, pushing eligible products onto the stack, and popping products from the stack while displaying them. The program prompts the user for choices to execute these functionalities.

Uploaded by

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

STACK

The document outlines a menu-driven program for managing a list of products, allowing users to add products, push products with prices below 500 into a stack, and pop all elements from the stack. It includes functions for product input, pushing eligible products onto the stack, and popping products from the stack while displaying them. The program prompts the user for choices to execute these functionalities.

Uploaded by

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

Write a menu driven program to create a list of products and push the product

names and price as a node, whose prices are below 500 into the stack. Also pop all
the elements as well as display the elements. List description: [pid, pname, price]

stk=[]
l=[]
def products():
n=int(input("enter no. of records: "))
for i in range(n):
pid=int(input("enter product id: "))
pname=input("enter product name: ")
price=int(input("enter price: "))
l.append([pid,pname,price])

def push():
for i in l:
if i[-1]<500:
stk.append([i[1],i[-1]])

for i in range(len(stk)-1,-1,-1):
print(stk[i])
else:
print("stack bottom")

def pop():
if len(stk):
while stk:
print(stk.pop())
else:
print("stack empty ")
else:
print("underflow")

print("""(i) Add products


(ii) To push elements into stack
(iii) To pop elements of a stack """)
c=input("enter a choice: ")
if c=='1':
products()
elif c=='2':
push()
elif c=='3':
pop()
else:
print("Invalid choice")
print()

You might also like