Check sibling questions
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


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 12 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.