ordinal suffix of the letter of a word python 3.5.
<pre><code>import random
import string
import sys

vowels = ['a', 'e', 'i', 'o', 'u']
consonants = [x for x in string.ascii_lowercase if x not in vowels]
SelectedWords = ['TRAILER', 'LAPTOP', 'SUNFLOWER', 'SKIPPING', 'AIRPLANE', 'HOUR', 'POTATO', 'HUGE', 'TINY', 'GOOD', 'BAD', 'YES', 'NO', 'WAGON', 'QUESTION', 'LAGOON', 'CAT', 'DUCK', 'GOANNA', 'POSTER', 'FUTURE', 'PRINCESS', 'RHYTHM', 'SUDDENLY', 'SNOW', 'MAGNET', 'TOWEL', 'RUNNING', 'SPEAKER', 'QUICKLY']
word_map = {x:{'consonants':len([y for y in x.lower() if y in consonants]), 'vowels':len([y for y in x.lower() if y in vowels]), 'letters':len(x)} for x in SelectedWords}
</code></pre>

<p>the below is part of a loop that creates random questions from 4 choices and then assigns a word to those questions. </p>

<p>For this question when the program might get a results of what is the letter 5 of hospital, the user would then input a answer and then get a correct or incorrect response. What I'm trying to do is  get the ordinal suffix of  the letter as well . So the question could be "what is the 5th letter of hospital"</p>

<pre><code>        n = random.randint(1, len(x))
        correct = x[n-1]
        if sys.version.startswith('3'):
            ans = str(input('What is letter {} of "{}"?'.format(n, x)))
        else:
            ans = str(raw_input('What is letter {} of "{}"?'.format(n, x)))
</code></pre>

<p>If you are looking to convert 1 => 1st, 2 => 2nd, 3 => 3rd, etc... this is the easiest way I can think of.  This special cases 1, 2, 3 and all numbers ending in 1, 2 or 3 except 11, 12 and 13.</p>

<pre><code>num_suffix = lambda x: "{}{}".format(x, {1: "st", 2: "nd", 3: "rd"}.get(0 if 10 &gt; x &gt; 14 else x % 10, "th"))

for i in range(1, 40):
    print("{} =&gt; {}".format(i, num_suffix(i))

1 =&gt; 1st
2 =&gt; 2nd
3 =&gt; 3rd
4 =&gt; 4th
5 =&gt; 5th
6 =&gt; 6th
7 =&gt; 7th
8 =&gt; 8th
9 =&gt; 9th
10 =&gt; 10th
11 =&gt; 11th
12 =&gt; 12th
13 =&gt; 13th
14 =&gt; 14th
15 =&gt; 15th
16 =&gt; 16th
17 =&gt; 17th
18 =&gt; 18th
19 =&gt; 19th
20 =&gt; 20th
21 =&gt; 21st
22 =&gt; 22nd
23 =&gt; 23rd
24 =&gt; 24th
25 =&gt; 25th
26 =&gt; 26th
27 =&gt; 27th
28 =&gt; 28th
29 =&gt; 29th
30 =&gt; 30th
31 =&gt; 31st
32 =&gt; 32nd
33 =&gt; 33rd
34 =&gt; 34th
35 =&gt; 35th
36 =&gt; 36th
37 =&gt; 37th
38 =&gt; 38th
39 =&gt; 39th
</code></pre>

<p>And I think 0 is actually 0th, but not sure.  You could special case that as well.</p>

python python-3.x