STACK ASSIGNMENT
Q1. A list contains following record of customer :
[Customer_name, Room Type]
Write the following user defined functions to perform given operations on the stack
named 'Hotel' :
(i) Push_Cust() – To Push customers’ names of those customers who are staying in
‘Delux’ Room Type.
(ii) Pop_Cust() – To Pop the names of customers from the stack and display them.
Also, display “Underflow” when there are no customers in the
stack.
For example : If the lists with customer details are as follows :
["Siddarth", "Delux"]
["Rahul", "Standard"]
["Jerry", "Delux"]
The stack should contain
Jerry
Siddharth
The output should be:
Jerry
Siddharth
Underflow
Q2. Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary containing
details of vehicles – {Car_Name: Maker}.
The function should push the name of car manufactured by ‘TATA’ (including all
the possible cases like Tata, TaTa, etc.) to the stack.
For example:If the dictionary contains the following data :
Vehicle={"Santro":"Hyundai","Nexon":"TATA","Safari":"Tata"}
The stack should contain
Safari
Nexon
Q3. 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.
Q4. 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.
For example: If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”]
[“Murugan”,”77777777777”,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]
The stack should contain
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
The output should be:
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
Stack Empty
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}
The stack should contain:
Notebook
Pen
The output should be:
The count of elements in the stack is 2
Q6. Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list
push all numbers divisible by 5 into a stack implemented by using a list. Display
the stack if it has at least one element, otherwise display appropriate error
message.
Q7. Write a function in Python POP(Arr), where Arr is a stack implemented by a list of
numbers. The function returns the value deleted from the stack.
Q8. 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. For example:
If the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90,"TOM":82}
The output from the program should be:
TOM ANU BOB OM
Q9. Write the definition of a user defined function Push3_5(N) which accepts a list of
integers in a parameter N and pushes all those integers which are divisible by 3 or
divisible by 5 from the list N into a stack named Only3_5.