Computer Science - Class 12
Chapter 3 - Stacks

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

Go Ad-free

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