def num2eng(num):
    '''English representation of a number up to a trillion.
    '''
    num = str(int(num))  # Convert to string, throw if bad number
    if (len(num) / 3 >= len(_PRONOUNCE)):  # Sanity check
        return num
    elif num == '0':  # Zero is a special case
        return 'zero'
    pron = []  # Result accumulator
    first = True
    for pr, bits in zip(_PRONOUNCE, grouper(3, reversed(num), '')):
        num = ''.join(reversed(bits))
        n = int(num)
        bits = []
        if n > 99:  # Got hundred
            bits.append('%s hundred' % _SMALL[num[0]])
            num = num[1:]
            n = int(num)
            num = str(n)
        if (n > 20) and (n != (n // 10 * 10)):
            bits.append('%s %s' % (_SMALL[num[0] + '0'], _SMALL[num[1]]))
        elif n:
            bits.append(_SMALL[num])
        if len(bits) == 2 and first:
            first = False
            p = ' and '.join(bits)
        else:
            p = ' '.join(bits)
        if p and pr:
            p = '%s %s' % (p, pr)
        pron.append(p)
    return ', '.join(reversed(pron))
def num2eng ( num ) : num = str ( int ( num ) ) if ( len ( num ) / 3 >= len ( _PRONOUNCE ) ) : return num elif num == '0' : return 'zero' pron = [ ] first = True for pr , bits in zip ( _PRONOUNCE , grouper ( 3 , reversed ( num ) , '' ) ) : num = '' . join ( reversed ( bits ) ) n = int ( num ) bits = [ ] if n > 99 : bits . append ( '%s hundred' % _SMALL [ num [ 0 ] ] ) num = num [ 1 : ] n = int ( num ) num = str ( n ) if ( n > 20 ) and ( n != ( n // 10 * 10 ) ) : bits . append ( '%s %s' % ( _SMALL [ num [ 0 ] + '0' ] , _SMALL [ num [ 1 ] ] ) ) elif n : bits . append ( _SMALL [ num ] ) if len ( bits ) == 2 and first : first = False p = ' and ' . join ( bits ) else : p = ' ' . join ( bits ) if p and pr : p = '%s %s' % ( p , pr ) pron . append ( p ) return ', ' . join ( reversed ( pron ) )
English representation of a number up to a trillion.