Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Speech Module by artemrudenko
# migrated from python 2.7
def checkio(n):
if isinstance(n, int) and n > 0 and n < 1000:
f = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six',
7:'seven', 8:'eight', 9:'nine'}
d = {11:'eleven', 12:'twelve', 13:'thirteen', 14:'fourteen',
15:'fifteen', 16:'sixteen', 17:'seventeen', 18:'eighteen',
19:'nineteen'}
g = {1:'ten', 2:'twenty', 3:'thirty', 4:'forty', 5:'fifty',
6:'sixty', 7:'seventy', 8:'eighty', 9:'ninety'}
res = ''
if n/100 != 0:
res = f[n/100] + ' ' + 'hundred'
n %= 100
if n in d:
res = res + ' ' + d[n] if res != '' else d[n]
elif n / 10 != 0:
res = res + ' ' + g[n/10] if res != '' else g[n/10]
n %= 10
if n in f:
res = res + ' ' + f[n] if res != '' else f[n]
return res.lower().replace(' ', ' ')
else:
return str(n)
print("First", "Done" if checkio(4) == 'four' else "Wrong")
print("Second", "Done" if checkio(133) == 'one hundred thirty three' else "Wrong")
print("Third", "Done" if checkio(12)=='twelve' else "Wrong")
print("Fifth", "Done" if checkio(101)=='one hundred one' else "Wrong")
for i in [4, 101, 143, 12, 11, 21, 784, 112]:
print('\n' + checkio(i))
March 15, 2011
Comments: