import math
def calc(tokens):
t = tokens.pop(0)
if t == "+":
return calc(tokens) + calc(tokens)
elif t == "-":
return calc(tokens) - calc(tokens)
elif t == "*":
return calc(tokens) * calc(tokens)
elif t == "/":
return calc(tokens) / calc(tokens)
elif t == "^":
return calc(tokens) ** calc(tokens)
elif t == "%":
return calc(tokens) % calc(tokens)
elif t == "-l":
return math.log(calc(tokens))
elif t == "&":
return [calc(tokens), calc(tokens)]
elif t == "£":
A=calc(tokens)
B=calc(tokens)
return [A[0]+B[0], A[1]+B[1]]
elif t == "@":
A=calc(tokens)
B=calc(tokens)
return [[A[0]*B[0], A[0]*B[1]],[A[1]*B[0], A[1]*B[1]]]
elif t == "-s":
return math.sin((math.pi/calc(tokens)))
elif t == "-c":
return math.cos((math.pi/calc(tokens)))
elif t == "+s":
return math.asin(tokens)
elif t == "+c":
return math.acos(tokens)
elif t == "=":
return (calc(tokens) == calc(tokens))
else:
return float(t)
print(calc("= + 1 1 2".split()))
print(calc("£ & 1 2 & 2 1".split()))
print(calc("/ -l 8 -l 2".split()))
print(calc("+ 1 * 3 / -s 4 -c 4".split()))
To embed this project on your website, copy the following code and paste it into your website's HTML: