Advertisement
CR7CR7

task10

Sep 18th, 2022
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def convert(num):
  2.     units = ("zero", "one ", "two ", "three ", "four ","five ", "six ", "seven ","eight ", "nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ","sixteen ", "seventeen ", "eighteen ", "nineteen ")
  3.     tens =("", "", "twenty ", "thirty ", "forty ", "fifty ","sixty ","seventy ","eighty ","ninety ")
  4.  
  5.     if num < 0:
  6.         return "minus "+convert(-num)
  7.  
  8.     if num<20:
  9.         return  units[num]
  10.  
  11.     if num<100:
  12.  
  13.         return  tens[num // 10]  +units[int(num % 10)]
  14.  
  15.     if num<1000:
  16.         return units[num // 100]  +"hundred " +convert(int(num % 100))
  17.  
  18.    
  19. print(convert(999))
  20.  
  21. '''numbers   number as words
  22. 0           Zero
  23. 9           Nine
  24. 10          Ten
  25. 12          Twelve
  26. 19          Nineteen
  27. 25          Twenty five
  28. 98          Ninety eight
  29. 98          Ninety eight
  30. 273         Two hundred and seventy three
  31. 400         Four hundred
  32. 501         Five hundred and one
  33. 617         Six hundred and seventeen
  34. 711         Seven hundred and eleven
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement