Write push(books)and pops(books)methods in python to add books and remove books considering them to act as push and pop operations of stack.
Answers
Answered by
13
Push and Pop are operations of Stack:
Push: Adds item on to stack
Pop: Removes item from the stack
Always pop is done by taking out elements from the top. Push always pushes new item to the top.
class StackPushPop:
def __init__(self):
self.items = []
def pushitems(self, item):
self.items.append(item)
def popitems(self):
return self.items.pop()
s1=StackPushPop()
s1.pushitems(9)
s1.pushitems(‘Elephant’)
s1.pushitems(True)
//After pushing elements, the size of the stack
print(s1.size())
print(s1.isEmpty())
s1.push(9.3)
print(s1.popitems())
print(s1.popitems())
//After removing 2 items
print(s1.size())
Answered by
1
Go through the image.......,.............
Attachments:
Similar questions