Solution: Reverse Polish calculator (stack) with deque



examples/lists/reverse_polish_calculator_deque.py
from collections import deque

stack = deque()

while True:
    val = input(':')

    if val == 'x':
        break

    if val == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(a+b)
        continue

    if val == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(a*b)
        continue


    if val == '=':
        print(stack.pop())
        continue

    stack.append(float(val))