Answers for "stack loop"

0

stack loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Stack
def_init_(self):
self.items=[]
def is_empty(self):
        return self.items==[]
    def push(self, data):
        self.items.append(data)
    def pop(self):
        return self.items.pop()
s= Stack()
while True:
    print(‘push<value>’)
    print(‘pop’)
    print(‘quit’)
do= input(‘What would you like to do?’).split()
operation= do[0].strip().lower()
if operation== ‘push’:
s.push(int(do[1]))
elif operation== ‘pop’:
    if s.is_empty():
        print(‘Stack is empty’)
    else:
        print(‘Popped value:’, s.pop())
elif operation==’quit’:
break
Posted by: Guest on March-03-2022

Browse Popular Code Answers by Language