-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_Python.py
More file actions
30 lines (27 loc) · 847 Bytes
/
Stack_Python.py
File metadata and controls
30 lines (27 loc) · 847 Bytes
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
26
27
28
29
30
def main():
stack = []
while True:
input_line = input()
console_command = (input_line.split(' '))[0]
if console_command == 'push':
number = int(input_line.split(' ')[1])
stack.append(number)
print('ok')
if console_command == 'pop':
if len(stack) != 0:
print(stack.pop())
else:
print('stack is empty')
break
if console_command == 'back':
print(stack[len(stack)-1])
if console_command == 'size':
print(len(stack))
if console_command == 'clear':
del stack[:]
print('ok')
if console_command == 'exit':
print('bye')
break
if __name__ == '__main__':
main()