-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLucid.py
More file actions
50 lines (36 loc) · 1.1 KB
/
Lucid.py
File metadata and controls
50 lines (36 loc) · 1.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/python3
import sys
import numpy as np
# Complete the function below.
def superStack(operations):
sStack = []
def printOut():
if sStack: print(sStack[-1])
else: print("EMPTY")
for operation in operations:
opCode = operation.split()[0]
if opCode == "push":
sStack.append(int(operation.split()[1]))
printOut()
elif opCode == "pop":
sStack.pop()
printOut()
elif opCode == "inc":
addNum = int(operation.split()[2])
inc = int(operation.split()[1])
for i in range(inc):
sStack[i] += addNum
printOut()
if __name__ == "__main__":
operations_cnt = 0
operations_cnt = int(input())
operations_i = 0
operations = []
while operations_i < operations_cnt:
try:
operations_item = str(input())
except:
operations_item = None
operations.append(operations_item)
operations_i += 1
res = superStack(operations);