Question

I'm solving exercise 17 from Euler's project, which is about number spelling (GB). I searched the web for number spelling rules, but didn't find anything suitable.

Does anyone have a link to english number spelling rules (GB) (for example when to use/not to use 'and')?

For example, how to spell correctly 342?

Here is my function I wrote, can you find any errors?

def compose(x):
    digits = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
    eleven_to_twenty = ['', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
    decades = ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
    if x < 1000:
        if x < 100:
            if x < 20:
                if x <= 10:
                    return digits[x]
                else:
                    return eleven_to_twenty[x - 10]
            else:
                return decades[x / 10] + digits[x % 10]
        else:
            return digits[x / 100] + 'hundredand' + compose(x % 100)
    else:
        return 'onethousand' + compose(x % 1000)
Was it helpful?

Solution

From https://english.stackexchange.com/questions/10687/rule-for-adding-and-or-hyphens-between-numbers-that-are-spelled-out-fully-in-t

Three hundred and forty-two

Leaving out 'and' is more common in US English. Either is acceptable, but including 'and' is more correct.

Hyphenate all compound numbers between twenty-one and ninety-nine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top