Computer Science
Write add(Books) and delete(Books) methods in Python to add Books and Remove Books considering them to act as append() and pop() operations in Stack.
Python
Python Stack
9 Likes
Answer
def add(Books):
bookname = input("Enter the book name: ")
Books.append(bookname)
def delete(Books):
if Books == []:
print("Books is empty")
else:
print("Deleted Book", Books.pop())
Books = []
add(Books)
add(Books)
add(Books)
print("Initial Books Stack:", Books)
delete(Books)
print("Books Stack after deletion:", Books)
Output
Enter the book name: Three thousand stitches
Enter the book name: Wings of fire
Enter the book name: Ignited minds
Initial Books Stack: ['Three thousand stitches', 'Wings of fire', 'Ignited minds']
Deleted Book Ignited minds
Books Stack after deletion: ['Three thousand stitches', 'Wings of fire']
Answered By
3 Likes
Related Questions
Give the necessary declaration of a list implemented Stack containing float type numbers. Also, write a user-defined function to pop a number from this Stack.
A linear Stack called Directory contains the following information as contacts:
— Pin code of city
— Name of cityWrite add(Directory) and delete(Directory) methods in Python to add and remove contacts using append() and pop() operations in Stack.
Write AddClient(Client) and DeleteClient(Client) methods in Python to add a new client and delete a client from a list client name, considering them to act as insert and delete operations of the Queue data structure.
Write Addscore(Game) and Delscore(Game) methods in Python to add new Score in the list of score in a game and remove a score from a list of score of a game considering these methods to act as PUSH and POP operation of data structure Stack.