daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def numbertoordinal(number):
  2.     if number < 0 or number > 10001:
  3.         return None
  4.      
  5.     if number < 20: #determining suffix for < 20
  6.         if number < 10:
  7.             if number == 0:
  8.                 suffix =''
  9.             elif number == 1:
  10.                 suffix = 'st'
  11.             elif number == 2:
  12.                 suffix = 'nd'
  13.             elif number == 3:
  14.                 suffix = 'rd'
  15.             else:
  16.                 suffix = 'th'
  17.         else:
  18.             suffix = 'th'
  19.  
  20.     else:   #determining suffix for > 20
  21.         tens = str(number)
  22.         tens = tens[-2]
  23.         unit = str(number)
  24.         unit = unit[-1]
  25.         if tens == "1":
  26.            suffix = "th"
  27.         else:
  28.             if unit == "1":
  29.                 suffix = 'st'
  30.             elif unit == "2":
  31.                 suffix = 'nd'
  32.             elif unit == "3":
  33.                 suffix = 'rd'
  34.             else:
  35.                 suffix = 'th'
  36.     return str(number)+ suffix
  37. print(numbertoordinal(20))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top