Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Speech Module by Daniel_Pereira
def checkio(number):
numerals = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine',
10: 'ten',
11: 'eleven',
12: 'twelve',
13: 'thirteen',
14: 'fourteen',
15: 'fifteen',
16: 'sixteen',
17: 'seventeen',
18: 'eighteen',
19: 'nineteen',
20: 'twenty',
30: 'thirty',
40: 'forty',
50: 'fifty',
60: 'sixty',
70: 'seventy',
80: 'eighty',
90: 'ninety',
'e0': '',
'e2': 'hundred',
'e3': 'thousand',
'e6': 'million',
'e9': 'billion',
'e12': 'trillion',
'e15': 'quadrillion',
'e18': 'quintillion',
'e21': 'sextillion',
'e24': 'septillion',
'e27': 'octillion',
'e30': 'nonillion',
}
if number in numerals:
return numerals[number]
compound_numeral = list()
for exp in reversed(range(0, len(str(number)), 3)):
group, group_remainder = divmod(number, 10 ** exp)
if group:
hundreds, remainder = divmod(group, 100)
if hundreds:
compound_numeral.append(numerals[hundreds])
compound_numeral.append(numerals['e2'])
if remainder:
if remainder in numerals:
compound_numeral.append(numerals[remainder])
else:
tens, ones = divmod(remainder, 10)
compound_numeral.append(numerals[tens * 10])
compound_numeral.append(numerals[ones])
compound_numeral.append(numerals['e{}'.format(exp)])
number = group_remainder
return ' '.join(compound_numeral).rstrip()
July 17, 2015