Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
straight forward solution in Clear category for Speech Module by alexkindel
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"
ZERO = "zero"
def checkio(number):
if number == 0:
return ZERO
# get digits
digits = []
while number > 0:
digits += [number % 10]
number //= 10
print( digits )
words = []
ones_digit = digits[0]
tens_digit = digits[1] if len( digits ) >= 2 else 0
hundreds_digit = digits[2] if len( digits ) >= 3 else 0
if hundreds_digit != 0:
words.append( FIRST_TEN[ hundreds_digit ] )
words.append( HUNDRED )
if tens_digit != 0:
if tens_digit >= 2:
words.append( OTHER_TENS[ tens_digit ] )
if ones_digit != 0:
words.append( FIRST_TEN[ ones_digit ] )
else:
words.append( SECOND_TEN[ones_digit] )
elif ones_digit != 0:
words.append( FIRST_TEN[ ones_digit ] )
phonetic_number = " ". join( words )
return phonetic_number
Oct. 1, 2015