# [Tutor] Projects (fwd)

Tiger12506 keridee at jayco.net
Thu Jan 24 01:37:22 CET 2008

```> up to a thousand (not tested)
>
> words = {0:'zero', 1:'one', 2:'two', 3:'three', ... , 10:'ten',
> 11:'eleven', 12:'twelve', ..., 19:'nineteen',
>         20:'twenty', ...., 90:'ninety', 100:'one hundred' }
> def digitToString(n) :
>    try :
>        retStr = words[n]
>    except KeyError :
>        if n > 100 :
>            retStr = (digitToString(n // 100)
>                     + ' hundred and '
>                     + digitToString(n % 100))
>        else :
>            retStr = (digitToString(n - (n % 10))
>                     + ' '
>                     + digitToString(n % 10))
>
>    return retStr

This could be written much more efficiently. It can be done with only these
lists~
ones =
['zero','one','two','three','four','five','six','seven','eight','nine']
teens =
['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
tens =
['','','twenty','thirty','fourty','fifty','sixty','seventy','eighty','ninety']
hundstr = 'hundred'
thousand = 'thousand'

Exercise for reader to make it work ;-) Unless of course you genuinely want
to see my code...
Current range 0 - 999,999    Easily extendable to millions, trillions,
billions, etc.

```