1. A particular stack is being implemented as a list (named Books), where every element
is again a list containing two pieces of information - book_no and title. Write the functions Push(Books) and
Pop(Books) to add a new book and to delete a book considering them as push and pop operations of the
stack data structure. Note: Ask the user input in the Push(Books) function itself.
Answers
Answered by
4
def Push(Books):
no, title = int(input("no: ")), input("title: ")
return Books.append([no, title])
def Pop(Books):
if len(Books) > 0:
item = Books[-1]
print(item)
return Books.remove(item)
Books = []
for _ in range(5):
Push(Books)
for _ in range(5):
Pop(Books)
Similar questions