Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views1 page

English Worksheet 2

The document outlines the creation of user-defined functions in Python for managing a stack of book records named BooksStack, including functions to push, pop, and peep at book records. Alternatively, it describes a function to push even integers from a list into a stack called EvenNumbers, along with functions to pop the top number and display all elements. Each function includes handling for empty stack scenarios with appropriate messages.

Uploaded by

Alan Lewis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

English Worksheet 2

The document outlines the creation of user-defined functions in Python for managing a stack of book records named BooksStack, including functions to push, pop, and peep at book records. Alternatively, it describes a function to push even integers from a list into a stack called EvenNumbers, along with functions to pop the top number and display all elements. Each function includes handling for empty stack scenarios with appropriate messages.

Uploaded by

Alan Lewis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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'.

OR

(B) 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'.

You might also like