SHARE
TWEET

Untitled

a guest May 16th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. num2words1 = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', \
  2.             6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', \
  3.             11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', \
  4.             15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen'}
  5. num2words2 = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
  6.  
  7.  
  8. def number(Number):
  9.     if Number == 0:
  10.         return f'zero'
  11.     elif 1 <= Number < 19:
  12.         return num2words1[Number]
  13.     elif 20 <= Number <= 99:
  14.         if Number % 10 == 0:
  15.             tens = int(Number / 10)
  16.             return num2words2[tens - 2]
  17.         else:
  18.             tens, below_ten = divmod(Number, 10)
  19.             return num2words2[tens - 2] + ' ' + num2words1[below_ten]
  20.     elif Number == 100:
  21.         return f'one hundred'
  22.     else:
  23.         print("Number out of range")
  24.  
  25.  
  26. def main():
  27.     num = eval(input())
  28.     print(number(num))
  29.  
  30.  
  31. main()
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