Exception Handling & Generate Functions

Question

Write Addnew(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

class stack:
	Book=[]
	def Addnew(self):
		Name=input('Enter Book Name :')
		stack.Book.append(Name)
	def Remove(self):
		if (stack.Book==[]):
			print 'Stack Empty'
		else:
			print 'Deleted Book is : ',stack.Book.pop()

Sponsor Area