Last active
December 30, 2015 01:48
-
-
Save alvaromuir/7758004 to your computer and use it in GitHub Desktop.
Python Ordinals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ordinal(n): | |
if 4 <= n <= 20 or 24 <= n <= 30: | |
return n + 'th' | |
else: | |
return str(n) + ["st", "nd", "rd"][n % 10 - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment