Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
_φ( °-°)/ solution in Clear category for Speech Module by vmiimu
import math
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"]
def checkio(n):
res, ones = [], n%10
tens, hundreds = n%100-ones, math.floor(n/100)%10
if hundreds: res.append(f'{FIRST_TEN[hundreds-1]} hundred')
if tens:
if tens < 20: return ' '.join(res + [SECOND_TEN[list(range(10,20)).index(tens+ones)]])
else: res.append(OTHER_TENS[list(range(20,91,10)).index(tens)])
if ones: res.append(FIRST_TEN[ones-1])
return ' '.join(res)
Jan. 28, 2019
Comments: