Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Speech Module by mozurin
import functools
def checkio(number):
def to_words(state, wdef):
if state[1] // wdef[0]:
state[0].append(wdef[1])
state[1] %= wdef[0]
return state
stringified = functools.reduce(
to_words,
(
(90, 'ninety'), (80, 'eighty'), (70, 'seventy'),
(60, 'sixty'), (50, 'fifty'), (40, 'forty'),
(30, 'thirty'), (20, 'twenty'),
(19, 'nineteen'), (18, 'eighteen'), (17, 'seventeen'),
(16, 'sixteen'), (15, 'fifteen'), (14, 'fourteen'),
(13, 'thirteen'), (12, 'twelve'), (11, 'eleven'),
(10, 'ten'), (9, 'nine'), (8, 'eight'),
(7, 'seven'), (6, 'six'), (5, 'five'),
(4, 'four'), (3, 'three'), (2, 'two'),
(1, 'one'),
),
[[], number % 100]
)[0]
if number >= 100:
stringified.insert(0, f'{checkio(number // 100)} hundred')
return ' '.join(stringified)
June 30, 2018
Comments: