Skip to content

Instantly share code, notes, and snippets.

@rswift
Created August 19, 2022 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rswift/936a762ee40b42788230cf737785443b to your computer and use it in GitHub Desktop.
Save rswift/936a762ee40b42788230cf737785443b to your computer and use it in GitHub Desktop.
Determine a day of the month ordinal...
def day_ordinal(day: int) -> str:
"""For a given day of the month, return its ordinal 📅"""
if 4 <= day <= 20 or 24 <= day <= 30:
return "th"
else:
return ["st", "nd", "rd"][day % 10 - 1]
for day in range(1, 31+1):
print(f"{day}{day_ordinal(day)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment