STACK WORKSHEET
1. 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'.
2. 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]
3. Write a function in Python, Push(KItem), where KItem is a dictionarycontaining the details of Kitchen
items– {Item:price}.
The function should push the names of those items in a stack which have priceless than 100. Also display
the average price of elements pushed into thestack.
For example: If the dictionary contains the following data:
{"Spoons":116,"Knife":50,"Plates":180,"Glass":60}
The stack should contain
Glass
Knife
The output should be: The average price of an item is 55.0