Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Speech Module by PawlakBartosz43
FIRST_TEN = ["one", "two", "three", "four", "five", "six", "seven",
"eight", "nine"]
SECOND_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"]
OTHER_TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"]
HUNDRED = "hundred"
def checkio(number):
number = str(number)
if(len(number)==1):
return FIRST_TEN[int(number)-1]
elif(len(number)==2):
if(int(number)<20):
return SECOND_TEN[int(number)-10]
else:
if(number[1]=='0'):
return OTHER_TENS[int(number[0])-2]
else:
return OTHER_TENS[int(number[0])-2]+" "+FIRST_TEN[int(number[1])-1]
elif(len(number)==3):
lastNumber = number[1:]
first = FIRST_TEN[int(number[0])-1]+" "+HUNDRED+" "
if(int(lastNumber)==0):
return FIRST_TEN[int(number[0])-1]+" "+HUNDRED
if(int(lastNumber)<10):
return first+FIRST_TEN[int(lastNumber[1])-1]
elif(int(lastNumber)<20):
return first+SECOND_TEN[int(lastNumber)-10]
else:
if(lastNumber[1]=='0'):
return first+OTHER_TENS[int(lastNumber[0])-2]
else:
return first+OTHER_TENS[int(lastNumber[0])-2]+" "+FIRST_TEN[int(lastNumber[1])-1]
return 'string representation of n'
Jan. 16, 2017