0% found this document useful (0 votes)
19 views4 pages

Stack

The document outlines a series of programming tasks focused on stack operations using Python. It includes user-defined functions for pushing and popping elements based on specific criteria, such as even numbers, customer details, and student marks. Each task specifies the input data structure and the expected behavior of the functions, emphasizing stack management and data filtering.

Uploaded by

pariaharshit
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)
19 views4 pages

Stack

The document outlines a series of programming tasks focused on stack operations using Python. It includes user-defined functions for pushing and popping elements based on specific criteria, such as even numbers, customer details, and student marks. Each task specifies the input data structure and the expected behavior of the functions, emphasizing stack management and data filtering.

Uploaded by

pariaharshit
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/ 4

Q1 CBSE 2025-26 SQP

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:

Q2

Q3 .Write the definition of a user-defined function def push_even(N):


`push_even(N)` which accepts a list of integers in a parameter EvenNumbers = []
`N` and pushes all those integers which are even from the list for num in N:
`N` into a Stack named `EvenNumbers`. Write function if num % 2 == 0:
pop_even() to pop the topmost number from the stack and EvenNumbers.append(num)
returns it. If the stack is already empty, the function should return EvenNumbers
display "Empty". Write function Disp_even() to display all
element of the stack without deleting them. If the stack is VALUES = []
empty, the function should display 'None'. for i in range(5):
For example: If the integers input into the list `VALUES` are: VALUES.append(int(input("Enter an integer: ")))
[10, 5, 8, 3, 12] EvenNumbers = push_even(VALUES)
Then the stack `EvenNumbers` should store:
[10, 8, 12] def pop_even():
if not EvenNumbers:
print("Underflow")
else: print(EvenNumbers.pop())
pop_even()

def Disp_even():
if not EvenNumbers:
print("None")
else:
print(EvenNumbers[::-1])
Disp_even()
Q4.
A list, NList contains following record as list elements:
[City, Country, distance from Delhi]
Each of these records are nested together to form a nested
list. Write the following user defined functions in Python to
perform the specified operations on the stack named
travel. (i) Push_element(NList): It takes the nested list as an
argument and pushes a list object containing name of the
city and country, which are not in India and distance is less
than 3500 km from Delhi. (ii) Pop_element(): It pops the
objects from the stack and displays them. Also, the
function should display “Stack Empty” when there are no
elements in the stack

Q5.
Write a function in Python, Push(SItem) where , SItem is a
dictionary containing the details of stationary items–
{Sname:price}. The function should push the names of
those items in the stack who have price greater than 75.
Also display the count of elements pushed into the stack.
For example: If the dictionary contains the following data:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}

Q6.
A list contains following record of a customer:
[Customer_name, Phone_number, City]
Write the following user defined functions to perform
given operations on the stack named ‘status’:
(i) Push_element() - To Push an object containing
name and Phone number of customers who live
in Goa to the stack
(ii) Pop_element() - To Pop the objects from the
stack and display them. Also, display “Stack
Empty” when there are no elements in the stack.
Q7.
Julie has created a dictionary containing names and marks
as key value pairs of 6 students. Write a program, with
separate user defined functions to perform the following
operations: ● Push the keys (name of the student) of the
dictionary into a stack, where the corresponding value
(marks) is greater than 75. ● Pop and display the content
of the stack.

Q8.Alam has a list containing 10 integers. You need to N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
help him create a program with separate user defined def PUSH(S,N):
functions to perform the following operations based on S.append(N)
this list. ● Traverse the content of the list and push the
even numbers into a stack. ● Pop and display the content
of the stack

Q9.Given a Dictionary Stu_dict containing marks of


students for three test-series in the form Stu_ID:(TS1, TS2, Stu_dict={5:(87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,8
TS3) as key-value pairs. Write a Python program with the 18:(80,48,91)}
following user-defined functions to perform the specified
operations on a stack named Stu_Stk
(i) Push_elements(Stu_Stk, Stu_dict) : It allows
pushing IDs of those students, from the
dictionary Stu_dict into the stack Stu_Stk, who
have scored more than or equal to 80 marks in
the TS3 Test.
(ii) Pop_elements(Stu_Stk): It removes all elements
present inside the stack in LIFO order and prints
them. Also, the function displays 'Stack Empty'
when there are no elements in the stack. Call
both functions to execute queries.
For example: If the dictionary Stu_dict contains the
following data:
Stu_dict ={5:(87,68,89), 10:(57,54,61), 12:(71,67,90),
14:(66,81,80), 18:(80,48,91)}
After executing Push_elements(), Stk_ID should contain
[5,12,14,18]
After executing Pop_elements(), The output should be:
18
14
12
5
Stack Empty

You might also like