Advertisement
sphinx2001

english_numbers

Jan 16th, 2021
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. def number_in_english(number):
  2.     Numbers = [None, 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
  3.                'eleven', 'twelve', 'thirteen', 'fourteen', 'fifthteen', 'sixteen', 'seventeen', 'eighteen',
  4.                'nineteen']
  5.     Tens = [None, None, 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
  6.     number_1_99 = number % 100
  7.     hundreds = number // 100
  8.     if number == 0:
  9.         return 'zero'
  10.     result = ''
  11.     if hundreds > 0:
  12.         if number_1_99 == 0:
  13.             return Numbers[hundreds] + ' hundred'
  14.         result = Numbers[hundreds] + ' hundred and '
  15.     if number_1_99 < 20:
  16.         return result + Numbers[number_1_99]
  17.     tens = number_1_99 // 10
  18.     digits = number_1_99 % 10
  19.     if digits == 0:
  20.         return result + Tens[tens]
  21.     else:
  22.         return result + Tens[tens] + ' ' + Numbers[digits]
  23.  
  24. print(number_in_english(100).lower())
  25. print(number_in_english(831).lower())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement