Question:
A list containing records of products as
L = [(“Laptop”, 90000), (“Mobile”, 30000), (“Pen”, 50), (“Headphones”, 1500)]
Write the following user-defined functions to perform operations on a stack named
Product to:
3
*Please note that the assessment scheme of the Academic Session 2024-25 will continue in the current session i.e.
2025-26.
Page 5
I. Push_element() – To push an item containing the product name and price of
products costing more than 50 into the stack.
Output: [(‘Laptop’, 90000), (‘Mobile’, 30000), (‘Headphones’, 1500)]
II. Pop_element() – To pop the items from the stack and display them. Also, display
“Stack Empty” when there are no elements in the stack.
Output:
(‘Headphones’, 1500)
(‘Mobile’, 30000)
(‘Laptop’, 90000)
Stack Emply
Answer:
I.
L = [(“Laptop”, 90000), (“Mobile”, 30000), (“Pen”, 50), (“Headphones”, 1500)]
product = []
def Push_element(L):
for i in L:
if i[1] > 50:
product.append(i)
print(product)
II.
def Pop_element(product):
while product:
print(product.pop())
else:
print(“Stack Emply”)
