Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, the dead-simple way to do it is to make a list of all the numbers you're interested in:</p> <pre><code>numbers = ["zero", "one", "two", "three", "four", "five", ... "ninety-eight", "ninety-nine"] </code></pre> <p>(The ... indicates where you'd type the text representations of other numbers. No, Python isn't going to magically fill that in for you, you'd have to type all of them to use that technique.)</p> <p>And then to print the number, just print <code>numbers[i]</code>. Easy peasy.</p> <p>Of course, that list is a lot of typing, so you might wonder about an easy way to generate it. English unfortunately has a lot of irregularities so you'd have to manually put in the first twenty (0-19), but you can use regularities to generate the rest up to 99. (You can also generate some of the teens, but only <em>some</em> of them, so it seems easiest to just type them in.)</p> <pre><code>numbers = "zero one two three four five six seven eight nine".split() numbers.extend("ten eleven twelve thirteen fourteen fifteen sixteen".split()) numbers.extend("seventeen eighteen nineteen".split()) numbers.extend(tens if ones == "zero" else (tens + "-" + ones) for tens in "twenty thirty forty fifty sixty seventy eighty ninety".split() for ones in numbers[0:10]) print numbers[42] # "forty-two" </code></pre> <p>Another approach is to write a function that puts together the correct string each time. Again you'll have to hard-code the first twenty numbers, but after that you can easily generate them from scratch as needed. This uses a little less memory (a <em>lot</em> less once you start working with larger numbers).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload