Check sibling questions

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()

 


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()

  1. Computer Science - Class 12
  2. Chapter 3 - Stacks

About the Author

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo