Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
411 B
3
Indexable
Never
import operator

ops = {
    '+' : operator.add,
    '-' : operator.sub,
    '*' : operator.mul,
    '/' : operator.truediv,
    '%' : operator.mod,
    '^' : operator.xor,
}
a = "14+3"
stack = []
num = ""
for ch in a:
    if ch in "+-/*":
        op = ch
        stack.append(num)
        stack.append(op)
        num = ""
    else:
        num += ch
op = stack.pop()
print(ops[op](int(stack.pop()),int(num)))