[Tutor] correcting an Active State Recipe for conversion to ordinal
Serdar Tumgoren
zstumgoren at gmail.com
Thu Feb 4 19:07:04 CET 2010
> No time to search for the issue, but here are some trials (hole from 10 --> 19):
> for i in range(21):
> print "%s\t: %s" %(i,ordinal(i))
> for i in (-1,22,33,99,100,101,199,200,999,1000):
> print "%s\t: %s" %(i,ordinal(i))
> ==>
> 0 : 0th
> 1 : 1st
> 2 : 2nd
> 3 : 3rd
> 4 : 4th
> 5 : 5th
> 6 : 6th
> 7 : 7th
> 8 : 8th
> 9 : 9th
> 10 : None
> 11 : None
> 12 : None
> 13 : None
> 14 : None
> 15 : None
> 16 : None
> 17 : None
> 18 : None
> 19 : None
> 20 : 20th
> -1 : -1th
> 22 : 22nd
> 33 : 33rd
> 99 : 99th
> 100 : 100th
> 101 : 101st
> 102 : 102nd
> 103 : 103rd
> 199 : 199th
> 200 : 200th
> 999 : 999th
> 1000 : 1000th
>
Okay, this is *really* strange. I performed the exact same tests as
above in IPython and I'm getting correct results (though I'm
embarrassed to admit I didn't consider negative numbers and doubly
embarrassed to admit that I'm not certain whether those should be a
mirror image of the positves...).
Below are the results I'm getting. Is it at all possible that this
could be a bug specific to my Python version, operating system or
something similar? I'll admit, this one's a bit over my head...
In [4]: for i in range(21):
...: print ordinal(i)
...:
...:
0th
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
In [5]: for i in (-1,22,33,99,100,101,199,200,999,1000):
...: ordinal(i)
...:
...:
Out[5]: u'-1th'
Out[5]: u'22nd'
Out[5]: u'33rd'
Out[5]: u'99th'
Out[5]: u'100th'
Out[5]: u'101st'
Out[5]: u'199th'
Out[5]: u'200th'
Out[5]: u'999th'
Out[5]: u'1000th'
In [7]: for i in range(21):
...: print "%s\t: %s" %(i,ordinal(i))
...:
0 : 0th
1 : 1st
2 : 2nd
3 : 3rd
4 : 4th
5 : 5th
6 : 6th
7 : 7th
8 : 8th
9 : 9th
10 : 10th
11 : 11th
12 : 12th
13 : 13th
14 : 14th
15 : 15th
16 : 16th
17 : 17th
18 : 18th
19 : 19th
20 : 20th
More information about the Tutor
mailing list