#please enter a number between 0 and 9,999,999,999 without comma!
num1 = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight",
9: "nine"}
num2 = {10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen",
16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 2: "twenty", 3: "thirty",
4: "forty", 5: "fifty", 6: "sixty", 7: "seventy", 8: "eighty", 9: "ninety"}
num3 = {1: "one hundred", 2: "two hundred", 3: "three hundred", 4: "four hundred",
5: "five hundred", 6: "six hundred", 7: "seven hundred", 8: "eight hundred",
9: "nine hundred"}
num4 = {1: "thousand"}
num7 = {1: "million"}
num10 = {1: "billion"}
numbers = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight",
9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen",
15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen",
20: "twenty", 30: "thirty", 40: "fourteen", 50: "fifty", 60: "sixty", 70: "seventy",
80: "eighty", 90: "ninety", 100: "one hundred", 200: "two hundred", 300: "three hundred",
400: "four hundred", 500: "five hundred", 600: "six hundred", 700: "seven hundred",
800: "eight hundred", 900: "nine hundred", 1000: "one thousand", 1000000: "one million",
1000000000: "one billion"}
ui = input()
lui = len(ui)
def hundreds_digits(n):
if (n[1:]) == "00":
return num3[int(n[0])]
elif (n[:-1]) == "0":
return num1[int(n[2])]
elif (n[0]) == "0":
if (int(n[1:])) in numbers:
return numbers[int(n[1:])]
else:
return num2[int(n[1])] + " " + num1[int(n[2])]
elif (n[1]) == "0":
return num3[int(n[0])] + " " + num1[int(n[2])]
elif (n[2]) == "0":
return num3[int(n[0])] + " " + numbers[int(n[1:])]
else:
if n[1:] <= "20":
return num3[int(n[0])] + " " + numbers[int(n[1:])]
else:
return num3[int(n[0])] + " " + num2[int(n[1])] + " " + num1[int(n[2])]
def under_million(x, y):
if int(x) in y:
return y[int(x)]
elif lui == 2:
return num2[int(x[0])] + " " + num1[int(x[1])]
elif lui == 3:
return hundreds_digits(x)
elif lui == 4:
if x[1:] == "0":
return num1[int(x[0])] + " " + num4[1] + hundreds_digits(x[1:])
else:
return num1[int(x[0])] + " " + num4[1] + " " + hundreds_digits(x[1:])
elif lui == 5:
if int(x[:2]) in y and (x[2:]) == "000":
return y[int(x[:2])] + " " + num4[1]
elif int(x[:2]) in y and not (x[2:]) == "000":
return y[int(x[:2])] + " " + num4[1] + " " + hundreds_digits(x[2:])
else:
return num2[int(x[0])] + " " + num1[int(x[1])] + " " + num4[1] + " " + \
hundreds_digits(x[2:])
elif lui == 6:
if int(x[:3]) in y and (x[3:]) == "000":
return y[int(x[:3])] + " " + num4[1]
elif int(x[:3]) in y and not (x[3:]) == "000":
return y[int(x[:3])] + " " + num4[1] + " " + hundreds_digits(x[3:])
elif int(x[:3]) not in y and not (x[3:]) == "000":
return hundreds_digits(x[:3]) + " " + num4[1] + " " + hundreds_digits(x[3:])
else:
return hundreds_digits(x[:3]) + " " + num4[1]
def million(x):
if lui == 7:
if x[1:] == "000000":
return num1[int(x[0])] + " " + num7[1]
elif x[1:4] == "000":
return num1[int(x[0])] + " " + num7[1] + " " + hundreds_digits(x[4:])
else:
return num1[int(x[0])] + " " + num7[1] + " " + hundreds_digits(x[1:4]) + \
" " + num4[1] + " " + hundreds_digits(x[4:])
elif lui == 8:
if int(x[:2]) in numbers:
if x[2:] == "000000":
return numbers[int(x[:2])] + " " + num7[1]
elif x[2:5] == "000":
return numbers[int(x[:2])] + " " + num7[1] + " " + hundreds_digits(x[5:])
elif x[5:] == "000":
return numbers[int(x[:2])] + " " + num7[1] + " " + hundreds_digits(x[2:5]) + \
" " + num4[1]
else:
return numbers[int(x[:2])] + " " + num7[1] + " " + hundreds_digits(x[2:5]) + \
" " + num4[1] + " " + hundreds_digits(x[5:])
else:
if x[2:] == "000000":
return num2[int(x[0])] + " " + num1[int(x[1])] + " " + num7[1]
elif x[2:5] == "000":
return num2[int(x[0])] + " " + num1[int(x[1])] + " " + \
num7[1] + " " + hundreds_digits(x[5:])
elif x[5:] == "000":
return num2[int(x[0])] + " " + num1[int(x[1])] + " " + num7[1] + " " + \
hundreds_digits(x[2:5]) + " " + num4[1]
else:
return num2[int(x[0])] + " " + num1[int(x[1])] + " " + num7[1] + " " + \
hundreds_digits(x[2:5]) + " " + num4[1] + " " + hundreds_digits(x[5:])
elif lui == 9:
if int(x[:3]) in numbers:
if x[3:] == "000000":
return numbers[int(x[:3])] + " " + num7[1]
elif x[3:6] == "000":
return numbers[int(x[:3])] + " " + num7[1] + " " + hundreds_digits(x[6:])
elif x[6:] == "000":
return numbers[int(x[:3])] + " " + num7[1] + " " + hundreds_digits(x[3:6]) + \
" " + num4[1]
else:
return numbers[int(x[:3])] + " " + num7[1] + " " + hundreds_digits(x[3:6]) + \
" " + num4[1] + " " + hundreds_digits(x[6:])
else:
if x[3:] == "000000":
return hundreds_digits(x[:3]) + " " + num7[1]
elif x[3:6] == "000":
return hundreds_digits(x[:3]) + " " + num7[1] + " " + hundreds_digits(x[6:])
elif x[6:] == "000":
return hundreds_digits(x[:3]) + " " + num7[1] + " " + hundreds_digits(x[3:6]) + \
" " + num4[1]
else:
return hundreds_digits(x[:3]) + " " + num7[1] + " " + hundreds_digits(x[3:6]) + \
" " + num4[1] + " " + hundreds_digits(x[6:])
def billion(x):
if lui == 10:
if x[1:] == "000000000":
return num1[int(x[0])] + " " + num10[1]
elif x[4:] == "000000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[1:4]) + " " + \
num7[1]
elif x[1:4] and x[7:] == "000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[4:7]) + " " + \
num4[1]
elif x[1:7] == "000000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[7:])
elif x[1:4] == "000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[4:7]) + " " + \
num4[1] + " " + hundreds_digits(x[7:])
elif x[4:7] == "000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[1:4]) + " " + \
num7[1] + " " + hundreds_digits(x[7:])
elif x[7:] == "000":
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[1:4]) + " " + \
num7[1] + " " + hundreds_digits(x[4:7]) + " " + num4[1]
else:
return num1[int(x[0])] + " " + num10[1] + " " + hundreds_digits(x[1:4]) + " " + \
num7[1] + " " + hundreds_digits(x[4:7]) + " " + num4[1] + " " + \
hundreds_digits(x[7:])
if ui == "0":
print("zero")
elif lui <= 6:
print(under_million(ui, numbers))
elif 10 > lui > 6:
print(million(ui))
elif lui > 9:
print(billion(ui))
Post a Comment