Created
November 23, 2023 22:01
-
-
Save JadeGrey/8e0b70ef19d7c5118a18f00a60c0da69 to your computer and use it in GitHub Desktop.
adds an ordinal to a defined number
This file contains hidden or 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): | |
suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)] | |
if 11 <= (n % 100) <= 13: | |
suffix = 'th' | |
return str(n) + suffix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment