#!/usr/bin/env python # -*- coding: utf-8 -*- # rpn.py # 逆ポーランド記法を使った電卓プログラム # 標準入力の行ごとに計算する import sys import string stack = [] def rpn(x): if x == '+': stack.append(stack.pop() + stack.pop()) elif x == '-': stack.append(stack.pop(-2) - stack.pop()) elif x == '*': stack.append(stack.pop() * stack.pop()) elif x == '/': stack.append(stack.pop(-2) / stack.pop()) else: stack.append(string.atof(x)) for s in sys.stdin.readlines(): s = s.strip() print s, l = s.split() stack = [] for x in l: rpn(x) print '=>', stack