Advertisement
lcast15

Python Number to Ordinal

Dec 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. def Ordinal(Num):
  2.     Num = str(Num)
  3.     if Num.endswith('1') and not Num.endswith('11'):
  4.         return Num + 'st'
  5.     elif Num.endswith('2') and not Num.endswith('12'):
  6.         return Num + 'nd'
  7.     elif Num.endswith('3') and not Num.endswith('13'):
  8.         return Num + 'rd'
  9.     else:
  10.         return Num + 'th'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement