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

549 people joined Teachoo Black. What are you waiting for?


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 - Teacher, Engineer, Marketer

Made by

Davneet Singh

Davneet Singh is a graduate from Indian Institute of Technology, Kanpur. He has been teaching from the past 12 years. He provides courses for Maths and Science at Teachoo.