0% found this document useful (0 votes)
53 views

Program For List Operation Using Stack: Source Code

This program uses a stack to manage a list of books. It allows the user to add multiple books to the list using a PUSH method or remove a single book from the end of the list using a POP method. The user is presented with a menu to repeatedly choose between these options or exit the program until selecting to exit.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Program For List Operation Using Stack: Source Code

This program uses a stack to manage a list of books. It allows the user to add multiple books to the list using a PUSH method or remove a single book from the end of the list using a POP method. The user is presented with a menu to repeatedly choose between these options or exit the program until selecting to exit.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM FOR LIST OPERATION USING STACK

SOURCE CODE:
book=[]

class Book:

def _init__(self):

self.num=0

self.name=''

def PUSH(self):

num=input('Enter the number of books u want to add:')

for i in range(num):

name=raw_input('Enter the name of the book:')

book.append(name)

def POP(self):

if(book==[]):

print 'The list is empty.'

else:

print 'The deleted book is', book.pop()

a=Book()

while True:

print 'Choose a command->'

print '1. To Add books.'

print '2. To remove a book.'

print '3. Exit.'


x=input('==>')

if x==1:

a.PUSH()

elif x==2:

a.POP()

elif x==3:

break

else:

print 'Enter a valid choice.'

OUTPUT:

You might also like