import operator as op, sys
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__":
while True:
exp = input("RPN > ")
if exp == "quit":
sys.exit()
else:
try:
print("{:.4f}".format(rpn(exp)))
except:
print("不正な入力です。")
finally:
exp
aW1wb3J0IG9wZXJhdG9yIGFzIG9wLCBzeXMKCnRhYmxlID0geycrJyA6IG9wLmFkZCwgJy0nIDogb3Auc3ViLCAnKicgOiBvcC5tdWwsICcvJyA6IG9wLnRydWVkaXZ9CgpkZWYgcnBuKGV4cCk6CiAgICBzdGFjayA9IFtdCiAgICBmb3IgdG9rZW4gaW4gZXhwLnNwbGl0KCk6CiAgICAgICAgdHJ5OiBzdGFjayArPSBbaW50KHRva2VuKV0KICAgICAgICBleGNlcHQgVmFsdWVFcnJvcjoKICAgICAgICAgICAgdHJ5OiBzdGFjayArPSBbZmxvYXQodG9rZW4pXQogICAgICAgICAgICBleGNlcHQgVmFsdWVFcnJvcjoKICAgICAgICAgICAgICAgIHN0YWNrID0gc3RhY2tbOi0yXSArIFt0YWJsZVt0b2tlbl0oKnN0YWNrWy0yOl0pXQogICAgcmV0dXJuIHN0YWNrWy0xXQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIHdoaWxlIFRydWU6CiAgICAgICAgZXhwID0gaW5wdXQoIlJQTiA+ICIpCiAgICAgICAgaWYgZXhwID09ICJxdWl0IjoKICAgICAgICAgICAgc3lzLmV4aXQoKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHRyeToKICAgICAgICAgICAgICAgIHByaW50KCJ7Oi40Zn0iLmZvcm1hdChycG4oZXhwKSkpCiAgICAgICAgICAgIGV4Y2VwdDoKICAgICAgICAgICAgICAgIHByaW50KCLkuI3mraPjgarlhaXlipvjgafjgZnjgIIiKQogICAgICAgICAgICBmaW5hbGx5OgogICAgICAgICAgICAgICAgZXhwCg==