Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Speech Module by volatilecat
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):
parts = []
hundreds = number // 100
tens = (number - hundreds * 100) // 10
ones = number - hundreds * 100 - tens * 10
if hundreds > 0:
parts.append(FIRST_TEN[hundreds - 1] + " " + HUNDRED)
if tens > 1:
parts.append(OTHER_TENS[tens - 2])
if ones > 0:
parts.append(FIRST_TEN[ones - 1])
elif tens == 1:
parts.append(SECOND_TEN[ones])
elif ones > 0:
parts.append(FIRST_TEN[ones - 1])
return " ".join(parts)
March 27, 2015