Pybites Logo

Return the right ordinal suffix for a number

Level: Intermediate (score: 3)

In this Bite you complete a function that takes an int and returns it appended with the right suffix: 1 -> 1st, 2 -> 2nd, 4 -> 4th, 11 -> 11th, etc.

As per Wikipedia the rules are:

  • -st is used with numbers ending in 1 (e.g. 1st, pronounced first)
  • -nd is used with numbers ending in 2 (e.g. 92nd, pronounced ninety-second)
  • -rd is used with numbers ending in 3 (e.g. 33rd, pronounced thirty-third). As an exception to the above rules, all the "teen" numbers ending with 11, 12 or 13 use -th (e.g. 11th, pronounced eleventh, 112th, pronounced one hundred [and] twelfth)
  • -th is used for all other numbers (e.g. 9th, pronounced ninth).

To focus on the exercise you can assume that the number inputted into the function is a positive int. Good luck and keep calm and code in Python!