Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Speech Module by vikulin
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):
result = []
tenths = number % 100
if number >= 100:
result.extend([FIRST_TEN[number // 100 - 1], HUNDRED])
if tenths >= 20:
result.append(OTHER_TENS[tenths // 10 - 2])
ones = tenths % 10 - 1
if ones >= 0:
result.append(FIRST_TEN[ones])
elif tenths > 0:
result.append((FIRST_TEN + SECOND_TEN)[tenths - 1])
return ' '.join(result)
Sept. 27, 2014
Comments: