[Tutor] Text numerals?
gew75 at hotmail.com
Sat May 15 22:25:09 EDT 2004
> Is there a function that will return 'one' for 1, 'two' for two, etc.?
I assume you mean 'two' for 2 ;). But no, AFAIK there is no stdlib
This question, although a different isomorphism, was asked recently.
The way I code such things is to use a dictionary.
Consider these statements:
# int y
x = 'stringresult'
if y == 1:
x = 'one'
elif y == 2:
x = 'two'
Consider that if you have a dictionary with key:value pairs similar to
that data above, you have a half-solution ready to go.
The problem of converting full-blown numbers of any length into letters is
much harder. Some years ago I remember this being coded in python; if the
author has a website, then Google is probably your best bet.
But make sure you need that kind of complexity; better to have a solution
you understand than one which is too powerful that you don't. It helps when
things go wrong ;).
More information about the Tutor