You are on page 1of 3

’’’

1.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:
SItem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
Notebook
Pen
The output should be:
The count of elements in the stack is 2’’’

#program
SItem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
stack=[]
def push():
for k in SItem:
if SItem[k]>75:
stack.append(k)
print(stack)
push()

’’’2.Vedika has created a dictionary containing names and marks as


key-value pairs of 5 students. Write a program, with separate user-defined
functions to perform the following operations:
(i) Push the keys (name of the student) of the dictionary into a stack,
where the corresponding value (marks) is greater than 70.
(ii) Pop and display the content of the stack.
The dictionary should be as follows:
d={"Ramesh":58, "Umesh":78, "Vishal":90, "Khushi":60,"Ishika":95}
Then the stack will be:
Umesh Vishal Ishika

3.A nested list contains the data of visitors in a museum. Each of the inner
lists contains the following data of a visitor:
[V_no (int), Date (string), Name (string), Gender (String M/F), Age (int)]
Write the following user defined functions to perform given operations on the stack
named "status":
(i) Push_element(Visitors) - To Push an object containing Gender of visitor
who are in the age range of 15 to 20.
(ii) Pop_element() - To Pop the objects from the stack and count and display
the number of Male and Female entries in the stack. Also, display “Done” when
there are no elements in the stack.
For example: If the list of Visitors contains:
[[’305’,"10/11/2022","Geeta",’F’,35],
[’306’, "10/11/2022","Arham",’M’, 15],
[’307’, "11/11/2022","David",’M’,18],
[’308’, "11/11/2022","Madhuri",’F’,17],
[’309’, "11/11/2022", "Sikandar",’M’,13]]
The output should be
F
M
M
The output should be:
Female: 1
Male: 2
Done’’’

visitors=[[’305’,"10/11/2022","Geeta",’F’,35],
[’306’, "10/11/2022","Arham",’M’, 15],
[’307’, "11/11/2022","David",’M’,18],
[’308’, "11/11/2022","Madhuri",’F’,17],
[’309’, "11/11/2022", "Sikandar",’M’,13]]

status=[]

def push_element(visitors):
for i in visitors:
if i[4]>=15 and i[4]<20:
status.append(i[3])
print(status)
push_element(visitors)

def pop_element():
Fc=Mc=0

while len(status)!=0:
e=status.pop()
print(e)
if e==’M’:
Mc+=1
else:
Fc+=1
print("Female:",Fc)
print("Male:",Mc)
print("Done")

pop_element()

’’’4.A list contains following record of a student:


[student_name, age, hostel]
Write the following user defined functions to perform given operations on the
stack named ‘stud_details’:
(i) Push_element() - To Push an object containing name and age of
students who live in hostel “Ganga” 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.
For example:
If the lists of customer details are:
[“Barsat”,17,”Ganga”]
[“Ruben”, 16,”Kaveri”]
[“Rupesh”,19,”Yamuna”]
The stack should contain
[“Barsat”,17,”Ganga”]
The output should be:
[“Barsat”,17,”Ganga”]
Stack Empty

5.A dictionary contains the names of some cities and their population in crore.
Write a python function push(stack, data), that accepts an empty list, which
is the stack and data, which is the dictionary and pushes the names of those
countries onto the stack whose population is greater than 25 crores.
For example :
The data is having the contents {’India’:140, ’USA’:50, ’Russia’:25, ’Japan’:10}
then the execution of the function push() should push India and USA on the
stack.

6.A list of numbers is used to populate the contents of a stack using a function
push(stack, data) where stack is an empty list and data is the list of numbers.
The function should push all the numbers that are even to the stack. Also
write the function pop(stack) that removes the elements of the stack on
its call. Also write the function calls.

7.A list named as Record contains following format of for students:


[student_name, class, city].
Write the following user defined functions to perform given operations on the
stack named ‘Record’:
(i) Push_record(Record) – To pass the list Record = [ [’Rahul’, 12,’Delhi’],
[‘Kohli’,11,’Mumbai’], [’Rohit’,12,’Delhi’] ] and then Push an object containing
Student name, Class and City of student belongs to ‘Delhi’ to the stack Record
and display and return the contents of stack
(ii) Pop_record(Record) – To pass following Record [[“Rohit”,”12”,”Delhi”]
[“Rahul”, 12,”Delhi”] ] and then to Pop all the objects from the stack and at last
display “Stack Empty” when there is no student record in the stack. Thus the
output should be: -
[“Rahul”, 12,”Delhi”]
[“Rohit”,”12”,”Delhi”]
Stack Empty’’’

You might also like