0% found this document useful (0 votes)
132 views2 pages

Book Stack Operations Program

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views2 pages

Book Stack Operations Program

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM FOR LIST OPERATION USING STACK

SOURCE CODE:
book=[]

class Book:

def _init__(self):

[Link]=0

[Link]=''

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:')

[Link](name)

def POP(self):

if(book==[]):

print 'The list is empty.'

else:

print 'The deleted book is', [Link]()

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:

[Link]()

elif x==2:

[Link]()

elif x==3:

break

else:

print 'Enter a valid choice.'

OUTPUT:

You might also like