Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Speech Module by dougall
def checkio(i):
if i < 20:
result = 'zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen'.split(',')[i]
elif i < 100:
result = ',,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety'.split(',')[i//10]
if i % 10:
result += ' ' + checkio(i % 10)
elif i < 1000:
result = checkio(i // 100) + ' hundred'
if i % 100:
result += ' ' + checkio(i % 100)
return result
if __name__ == '__main__':
assert checkio(4) == 'four', "First"
assert checkio(133) == 'one hundred thirty three', "Second"
assert checkio(12)=='twelve', "Third"
assert checkio(101)=='one hundred one', "Fifth"
assert checkio(212)=='two hundred twelve', 'Sixth'
print('All ok')
Nov. 15, 2012
Comments: