Write Add new(Book) and Remove(Book) methods in Python to Add a new Book and Remove a Book from a List of Books, considering them to act as PUSH and POP operations of the data structure stack.

 

Answer:

def addnew(Books):

str=input(print("Enter a book's name: "))

Books.append(str)

def remove(Books):

if len(Books)==0:

print("Stack is empty")

else:

Books.pop()

 

Slide29.JPG

Remove Ads

Transcript

Write Add new(Book) and Remove(Book) methods in Python to Add a new Book and Remove a Book from a List of Books, considering them to act as PUSH and POP operations of the data structure stack. Answer: def addnew(Books): str=input(print("Enter a book's name: ")) Books.append(str) def remove(Books): if len(Books)==0: print("Stack is empty") else: Books.pop()

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.