[Tutor] Is there an easily or shorter way?

Dave Angel davea at davea.name
Tue Dec 16 00:04:17 CET 2014

On 12/15/2014 05:49 PM, Steven D'Aprano wrote:
> On Mon, Dec 15, 2014 at 04:25:42PM -0500, Ken G. wrote:
>> I am sure there is a better way to refine the following lines.
>> Letting x equal a number from 1 to 28, go through 28 separate 'if'
>> statements to print a resulting value that equaled the value of x.

> Of course, as Danny suggested, if you're going to be using this
> seriously for arbitrary numbers, you can't possibly list every single
> one in advance. What if somebody asks for the name of 9274810276523? In
> that case, we need a function that turns a number into an name digit by
> digit:

>      nine trillion, two hundred and seventy-four billion,
>      eight hundred and ten million, two hundred and
>      seventy-six thousand, five hundred and twenty-three

That's using the American interpretation for billion and trillion, not 
the British one.

> Doing this makes a nice little programming exercise, so I will leave it
> to you :-)

"one, two, three, many"

We only need four values, in some societies...    ;-)


More information about the Tutor mailing list