2.1 a problem to be solved

Effectively a shortened version of project euler #17.

We want a function convert :: Int -> String which will convert a number n[0,1000000) to its english word representation.

In python, this is in converter.py

def convert(n: int) -> str:
    """
    Converts n (0 <= n < 10**6) to a string
    representation of the number in English.

    Args:
        n (int): integer between 0 and 10**6.
    
    Returns:
        str: string representation of the number in English.

    Raises:
        ValueError: if n is not between 0 and 10**6.        
    """
    endings = ['zero', 'one', 'two', 'three', 'four', 'five',
            'six', 'seven', 'eight', 'nine', 'ten',
            'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
            'sixteen', 'seventeen', 'eighteen', 'nineteen']
    tens = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
    powers_of_10 = ['', 'thousand', 'million']
    if n < 20:
        return endings[n]
    elif n < 100:
        if n % 10 == 0:
            return tens[n // 10 - 2]
        return tens[n // 10 - 2] + ' ' + endings[n % 10]
    elif n < 1000:
        if n % 100 == 0:
            return endings[n // 100] + ' hundred'
        return endings[n // 100] + ' hundred ' + convert(n % 100)
    for i in range(2, len(powers_of_10)):
        if n < 10**(3*i):
            if n % 10**(3*(i-1)) == 0:
                return convert(n // 10**(3*(i-1))) + ' ' + powers_of_10[i-1]
            return convert(n // 10**(3*(i-1))) + ' ' \
                    + powers_of_10[i-1] + ' ' \
                    + convert(n % 10**(3*(i-1)))
    raise ValueError("n must be less than 10**6")

Roughly, you handle the small numbers first since 0-19 determine the end of a string. Then, for larger numbers, you work by their powers (tens, hundreds) until you get to thousands, because then after that it becomes breaking it down into sections of three and adding the correct section label (in this case thousand).