Solved 2025 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 3
Back to all questionsYou 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:
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.
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".
peep(BookStack): This function displays the topmost element of the stack without deleting it. If the stack is empty, the function should display 'None'.
1.
def push_book(BooksStack, new_book):
BooksStack.append(new_book)2.
def pop_book(BooksStack):
if not BooksStack:
print("Underflow")
else:
return(BookStack.pop())3.
def peep(BooksStack):
if not BooksStack:
print("None")
else:
print(BookStack[-1])