#!/usr/bin/env python

class Numstr:

    def __init__(self, num=0, string=''):
        self.__num = num
        self.__string = string

    def update(self, num=None, string=None):
        if num != None:
            self.__num = num
        if string != None:
            self.__string = string

    def __str__(self):                # define for str()
        return '[%d :: %s]' % \
            (self.__num, `self.__string`)
    __repr__ = __str__

    def __add__(self, other):        # define for s+o
        if isinstance(other, Numstr):
            return self.__class__(self.__num + \
                other.__num,
                self.__string + other.__string)
        else:
            raise TypeError, \
                'illegal argument type for built-in operation'

    def __radd__(self, other):        # define for o+s
        if isinstance(other, Numstr):
            # add numbers and strings, create and return new object
            return self.__class__(other.num + self.num, other.str + self.str)
            # could also be (self.__num + other.__num, other.__string + self.__string)
        else:
            raise TypeError, 'illegal argument type for built-in operation'

    def __mul__(self, other):        # define for s*o
        if type(other) == type(0):
            return self.__class__(self.__num * other, self.__string * other)
        else:
            raise TypeError, 'illegal argument type for built-in operation'

    def __nonzero__(self):        # reveal tautology
        return self.__num and len(self.__string)

    def __normalize_cmpval(self, cmpres): # normalize cmp()
        return cmp(cmpres, 0)

    def __cmp__(self, other):        # define for cmp()
        nres = self.__normalize_cmpval(cmp(self.__num, \
            other.__num))
        sres = self.__normalize_cmpval(cmp(self.__string, \
            other.__string))

        if not (nres or sres): return 0 # both 0
        sum  = nres + sres
        if not sum: return None                # one <, one >
        return sum
