import operator as op
table = {'+' : op.add, '-' : op.sub, '*' : op.mul, '/' : op.truediv}
def rpn(exp):
stack = []
for token in exp.split():
try: stack += [int(token)]
except ValueError:
try: stack += [float(token)]
except ValueError:
stack = stack[:-2] + [table[token](*stack[-2:])]
return stack[-1]
if __name__ == '__main__':
exp = "6.1 5.2 4.3 * + 3.4 2.5 / 1.6 * -"
ans = rpn(exp)
print("{0} = {1:.4f}".format(exp, ans))
aW1wb3J0IG9wZXJhdG9yIGFzIG9wCgp0YWJsZSA9IHsnKycgOiBvcC5hZGQsICctJyA6IG9wLnN1YiwgJyonIDogb3AubXVsLCAnLycgOiBvcC50cnVlZGl2fQoKZGVmIHJwbihleHApOgogICAgc3RhY2sgPSBbXQogICAgZm9yIHRva2VuIGluIGV4cC5zcGxpdCgpOgogICAgICAgIHRyeTogc3RhY2sgKz0gW2ludCh0b2tlbildCiAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6CiAgICAgICAgICAgIHRyeTogc3RhY2sgKz0gW2Zsb2F0KHRva2VuKV0KICAgICAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6CiAgICAgICAgICAgICAgICBzdGFjayA9IHN0YWNrWzotMl0gKyBbdGFibGVbdG9rZW5dKCpzdGFja1stMjpdKV0KICAgIHJldHVybiBzdGFja1stMV0KCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBleHAgPSAiNi4xIDUuMiA0LjMgKiArIDMuNCAyLjUgLyAxLjYgKiAtIgogICAgYW5zID0gcnBuKGV4cCkKICAgIHByaW50KCJ7MH0gPSB7MTouNGZ9Ii5mb3JtYXQoZXhwLCBhbnMpKQo=