Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 5d28bc48 authored by Rachel D Frenkel's avatar Rachel D Frenkel
Browse files

week8

parent 90835dc7
#!/usr/bin/env python3
import operator
import math
operators = {
......@@ -9,24 +10,45 @@ operators = {
'*': operator.mul,
'/': operator.truediv,
'^': operator.pow,
'!': math.factorial,
}
prev = {}
numOps = 0
def calculate(myarg):
stack = list()
for token in myarg.split():
try:
if token[0] == ':':
if ans not in prev:
raise TypeError("ERROR")
token = prev['ans']
token = int(token)
stack.append(token)
except ValueError:
function = operators[token]
arg2 = stack.pop()
arg1 = stack.pop()
result = function(arg1, arg2)
stack.append(result)
if token == 'copy':
cpy = stack.pop()
stack.append()
stack.append()
if numOps > 0:
result = function(stack.pop())
stack.append(result)
else:
arg2 = stack.pop()
arg1 = stack.pop()
result = function(arg1, arg2)
stack.append(result)
numOps += 1
print(stack)
if len(stack) != 1:
raise TypeError("Too many parameters")
return stack.pop()
prev['ans'] = stack.pop()
return prev['ans']
def main():
while True:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment