0% found this document useful (0 votes)
7 views3 pages

STACK

The document is a worksheet for Computer Science students at Bonne Anne Public School, Moradabad, containing various programming tasks related to stack operations in Python. It includes functions for pushing and popping customer records, managing book records, handling even numbers, and manipulating student marks stored in a dictionary. Additionally, it provides examples and expected outputs for each task to guide students in their coding exercises.

Uploaded by

rosieposielisa03
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)
7 views3 pages

STACK

The document is a worksheet for Computer Science students at Bonne Anne Public School, Moradabad, containing various programming tasks related to stack operations in Python. It includes functions for pushing and popping customer records, managing book records, handling even numbers, and manipulating student marks stored in a dictionary. Additionally, it provides examples and expected outputs for each task to guide students in their coding exercises.

Uploaded by

rosieposielisa03
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/ 3

BONNE ANNE PUBLIC SCHOOL, MORADABAD

SUBJECT: COMPUTER SCIENCE


WORKSHEET (XII)
Q.1 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
Q.2 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
Q.3 A) You have a stack named BooksStack that contains records of books. Each
book record is represented as a list containing book_title, author_name, and
publication_year. Write the following user-defined functions in Python to perform
the specified operations on the stack BooksStack:
(I) push_book(BooksStack, new_book): This function takes the stack
BooksStack and a new book record new_book as arguments and pushes the new
book record onto the stack.
(II) pop_book(BooksStack): This function pops the topmost book record from
the stack and returns it. If the stack is already empty, the function should display
"Underflow".
(III) peep(BookStack): This function displays the topmost element of the stack
without deleting it. If the stack is empty, the function should display 'None'.
Q.4 Write the definition of a user-defined function `push_even(N)` which accepts a
list of integers in a parameter `N` and pushes all those integers which are even
from the list `N` into a Stack named `EvenNumbers`. Write function pop_even() to
pop the topmost number from the stack and returns it. If the stack is already
empty, the function should display "Empty". Write function Disp_even() to display
all element of the stack without deleting them. If the stack is empty, the function
should display 'None'
For example:
If the integers input into the list `VALUES` are:
[10, 5, 8, 3, 12]
Then the stack `EvenNumbers` should store:
[10, 8, 12]
Q.5 Write a function AddCustomer(Customer) in Python to add a new Customer
information NAME into the List of CStack and display the information.

Q.6 Write a function DeleteCustomer() to delete a Customer information from a list


of CStack. The function delete the name of customer from the stack.

Q.7 List out any two real-life examples of Stack.

Q.8 Consider STACK=[23,45,67,89,51]. Write the STACK content after each


operations:

1.STACK.pop( )
2.STACK.append(99)
3.STACK.append(87)
4.STACK.pop( )
Q.9 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:

1.Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
2.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
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82

Q.10 Evaluate following expression using stack operation: 5,6,7,8,*,+,17,/,10,+,-

You might also like