avatar 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!

Login and get coding
go back Intermediate level
Bitecoin 3X

139 out of 139 users completed this Bite.
Will you be Pythonista #140 to crack this Bite?
Resolution time: ~29 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 2.0 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help