Advertisement
ad2bg

SpellOutInt0to999InEN

Jun 9th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. def SpellOutInt0to999InEN(input):
  2.     and_ = False
  3.     en = ""
  4.     ones = ""
  5.     tens = ""
  6.     hundreds = ""
  7.  
  8.     if input // 100 == 0:
  9.         hundreds = ""
  10.     elif input // 100 == 1:
  11.         hundreds = "one hundred"
  12.     elif input // 100 == 2:
  13.         hundreds = "two hundred"
  14.     elif input // 100 == 3:
  15.         hundreds = "three hundred"
  16.     elif input // 100 == 4:
  17.         hundreds = "four hundred"
  18.     elif input // 100 == 5:
  19.         hundreds = "five hundred"
  20.     elif input // 100 == 6:
  21.         hundreds = "six hundred"
  22.     elif input // 100 == 7:
  23.         hundreds = "seven hundred"
  24.     elif input // 100 == 8:
  25.         hundreds = "eight hundred"
  26.     elif input // 100 == 9:
  27.         hundreds = "nine hundred"
  28.  
  29.     if (input % 100) // 10 == 0:
  30.         tens = ""
  31.     elif (input % 100) // 10 == 1:
  32.         tens = "ten"
  33.     elif (input % 100) // 10 == 2:
  34.         tens = "twenty"
  35.     elif (input % 100) // 10 == 3:
  36.         tens = "thirty"
  37.     elif (input % 100) // 10 == 4:
  38.         tens = "forty"
  39.     elif (input % 100) // 10 == 5:
  40.         tens = "fifty"
  41.     elif (input % 100) // 10 == 6:
  42.         tens = "sixty"
  43.     elif (input % 100) // 10 == 7:
  44.         tens = "seventy"
  45.     elif (input % 100) // 10 == 8:
  46.         tens = "eighty"
  47.     elif (input % 100) // 10 == 9:
  48.         tens = "ninety"
  49.  
  50.     if input % 10 == 0:
  51.         ones = ""
  52.     elif input % 10 == 1:
  53.         ones = "one"
  54.     elif input % 10 == 2:
  55.         ones = "two"
  56.     elif input % 10 == 3:
  57.         ones = "three"
  58.     elif input % 10 == 4:
  59.         ones = "four"
  60.     elif input % 10 == 5:
  61.         ones = "five"
  62.     elif input % 10 == 6:
  63.         ones = "six"
  64.     elif input % 10 == 7:
  65.         ones = "seven"
  66.     elif input % 10 == 8:
  67.         ones = "eight"
  68.     elif input % 10 == 9:
  69.         ones = "nine"
  70.  
  71.     if tens == "" and ones == "":
  72.         en = "zero" if hundreds == "" else hundreds
  73.  
  74.     elif tens == "ten":
  75.  
  76.         if ones == "":
  77.             en = "ten"
  78.         elif ones == "one":
  79.             en = "eleven"
  80.         elif ones == "two":
  81.             en = "twelve"
  82.         elif ones == "three":
  83.             en = "thirteen"
  84.         elif ones == "four":
  85.             en = "fourteen"
  86.         elif ones == "five":
  87.             en = "fifteen"
  88.         elif ones == "six":
  89.             en = "sixteen"
  90.         elif ones == "seven":
  91.             en = "seventeen"
  92.         elif ones == "eight":
  93.             en = "eighteen"
  94.         elif ones == "nine":
  95.             en = "nineteen"
  96.  
  97.         if hundreds != "":
  98.             en = hundreds + (" and " if and_ else " ") + en
  99.  
  100.     else:
  101.         en = ones
  102.         if tens != "":
  103.             en = tens + ("" if ones == "" else " " + en)
  104.         if hundreds != "":
  105.             en = hundreds + (" and " if and_ else " ") + en
  106.  
  107.     return en
  108.  
  109.  
  110. n = int(input())
  111. print(SpellOutInt0to999InEN(n) if 0 <= n <= 100 else "invalid number")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement