def int_to_str(number):
    '''Return integer as a spelled-out string.'''

    if not isNumber(number) and '-' not in str(number):
        raise ValueError('Input must be an integer')

    number = str(number)

    dollar_flag = False
    negative_flag = False

    while True:
        if number[0] == '$':
            dollar_flag = True
            number = number[1:]
        elif number[0] == '-':
            negative_flag = True
            number = number[1:]
        else:
            break

    number_conv_table = {

        '-' : 'negative',
        '$' : 'dollar',
        '0' : 'zero',
        '1' : 'one',
        '2' : 'two',
        '3' : 'three',
        '4' : 'four',
        '5' : 'five',
        '6' : 'six',
        '7' : 'seven',
        '8' : 'eight',
        '9' : 'nine',
        }

    number_conv_table_spec = {
        '0' : 'zero',
        '1' : 'zero',
        '2' : 'twenty',
        '3' : 'thirty',
        '4' : 'forty',
        '5' : 'fifty',
        '6' : 'sixty',
        '7' : 'seventy',
        '8' : 'eighty',
        '9' : 'ninety',
        }

    number_conv_table_ones = {
        '0' : 'ten',
        '1' : 'eleven',
        '2' : 'twelve',
        '3' : 'thirteen',
        '4' : 'fourteen',
        '5' : 'fifteen',
        '6' : 'sixteen',
        '7' : 'seventeen',
        '8' : 'eighteen',
        '9' : 'nineteen',
        }
    
    if str(number) in number_conv_table:
        if negative_flag:
            return 'negative '+number_conv_table[str(number)]
        else:
            return number_conv_table[str(number)]
    
    number = number[::-1]
    sectors = []

    for i in range(0, len(number), 3):
        sectors.append(number[i:i+3][::-1])

    sectors.reverse()

    flags = ['hundred', 'thousand', 'million', 'billion', 'trillion',
             'quadrillion', 'quintillion','sextillion', 'septillion', 'octillion',
             'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion',
             'quattuordecillion']

    output = []
    word = ''
    hundred_flag = False
    and_flag = False
    tens_flag = False
    sector_place = len(sectors)

    if negative_flag:
        output.append('negative')

    for sector in sectors:
            
        hundred_flag = False
        
        if len(sector) == 3 and int(sector[0]) > 0:
            hundred_flag = True

        nums_place = len(sector)
        
        for num in sector:

            if nums_place == 1 and tens_flag:
                word = number_conv_table_ones[num]
                tens_flag = False

            elif nums_place == 2:
                
                if num == '1':
                    tens_flag = True
                else:
                    word = number_conv_table_spec[num]

            else:
                word = number_conv_table[num]

            if word != 'zero' and len(number) > 1 and not tens_flag:
                output.append(word)
                    
            if hundred_flag:
                output.append('hundred')
                hundred_flag = False

            if sector_place > 1 and nums_place == 1 and sector != '000':
                if (sector_place - 1) < 16:
                    output.append(flags[sector_place-1])
                else:
                    raise RangeError('Input number too large.')

            nums_place -= 1

        sector_place -= 1

    if dollar_flag:
        output.append('dollars')

    return ' '.join(output)
Return integer as a spelled-out string.
recipes/Python/580689_Convert_Spelled_out_Integers_eg_three_thoustwo/recipe-580689.py