[Tutor] correcting an Active State Recipe for conversion to ordinal

Wayne Werner waynejwerner at gmail.com
Thu Feb 4 18:45:09 CET 2010


On Thu, Feb 4, 2010 at 11:11 AM, Serdar Tumgoren <zstumgoren at gmail.com>wrote:

> Hi folks,
> <snip>
> I just noticed, however, that in the comments section of the
> ActiveState recipe that someone is getting incorrect results for
> certain numbers (11 and 12, specifically).
>
> But when I use the code on my own machine it still works fine. So I
> was hoping that you all could help me "crowdsource" the issue. If you
> have the time and inclination, could you look at the code and tell me
> if and where I've gone wrong? And of course, if there's a simpler way
> to perform the conversion I'd be glad to update the recipe.  I
> certainly don't want something out in the wilds of the Web that's
> incorrect, inelegant or just plain confusing.
>
> Here's the link to the recipe:
>
> http://code.activestate.com/recipes/576888/
>
>
Well at first I was getting "None" for 11 and 12.  The following conversion
fixed that problem:

if value % 100/10 <> 1:

to

if value % 100/10.0 <> 1:

But I'm still getting weird output:

for x in (1,2,3,11,4, 12,19,101):
    print ordinal(x)

Follows:
1st
2nd
3rd
11st
4th
12nd
19th
101st


Where 11 and 12 should be 11th and 12th.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100204/55c8fd4c/attachment.htm>


More information about the Tutor mailing list