Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Speech Module by MMM_AAA_NNN
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):
hundreds = number / 100
last2digits = number % 100
result = ""
hspacer = " "*bool(hundreds)
if hundreds:
result += FIRST_TEN[hundreds-1] + " " + HUNDRED
if last2digits:
if last2digits < 10: result += hspacer + FIRST_TEN[last2digits-1]
elif last2digits < 20: result += hspacer + SECOND_TEN[last2digits-10]
else:
tens = last2digits/10
lastdigit = last2digits%10
result += hspacer + OTHER_TENS[tens-2]
if lastdigit: result+= " " + FIRST_TEN[lastdigit-1]
return result
March 23, 2015
Comments: