Bite 127. Return the right ordinal suffix for a number

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!

22 out of 22 users completed this Bite.
Will you be Pythonista #23 to crack this Bite?
Average Bite difficulty 1-10 rating: 2.0
» You can do it! 😌

Github login button
We use Python 3.7