Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
3 simple operations solution in Uncategorized category for Speech Module by odony
UNITS = ["zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine"]
OVER_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"]
TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"]
def checkio(number):
hundreds, remainder = divmod(number, 100)
tens, units = divmod(remainder, 10)
# construct the 4 possible parts of the result and filter out the empty ones
return ' '.join(filter(None,
['{0} hundred'.format(UNITS[hundreds]) if hundreds else '',
TENS[tens-2] if tens > 1 else '',
OVER_TEN[units] if tens == 1 else '',
UNITS[units] if (tens != 1 and units) or not number else '']))
June 5, 2013
Comments: