# addmach4.py
# Written by Todd Wareham for CS 2500
"""
Implements interactive adding machine with these commands:

    "+ X"  : Add floating number X to sum
    "- X"  : Subtract floating number X from sum
    "="    : Print value of sum
    "stop" : Exit session

This version is implemented using the Decimal numeric datatype,
 lambda expressions, and a dictionary-based function lookup table..
"""

op = {"+" : (lambda x, y: x + y), "-" : (lambda x, y: x - y)}
sum = Decimal("0.0")
while True:
    line = raw_input()
    if (line.split()[0] in ["+", "-"]):
        sum = op[line.split()[0]](sum, Decimal(line.split()[1]))
    elif (line.split()[0] == "="):
        print sum
    elif (line.split()[0] == "stop"):
        break

