#! /usr/bin/python
""" Terminal line program for fetch-and-add """
__author__ = "brock"

class FetchAndAdd(object):
    """ fetch-and-add """
    def __init__(self, initial=0):
        self._value = initial
    def add(self, incr):
        """ the add instruction """
        retv = self._value
        self._value = retv + incr
        return retv
    def __str__(self):
        return str(self._value)

def main():
    """ main routine """
    fad = FetchAndAdd()
    try:
        while 1:
            try:
                incr = int(input('Enter next number: '))
                print('  --> {0}'.format(fad.add(incr)))
            except ValueError:
                print('!!!!')
    except (EOFError, KeyboardInterrupt):
        pass

if __name__ == "__main__":
    main()
