Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Speech Module by Dirk
# migrated from python 2.7
FIRST_TEN = ["zero", "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"]
HUNDRED = "hundred"
print(305 // 100)
def checkio(number):
result = []
if number >= 100:
result.append(FIRST_TEN[number // 100] + " hundred")
if (number % 100) // 10 > 1:
result.append(OTHER_TENS[((number % 100) // 10) - 2])
if (number % 100) // 10 == 1:
result.append(SECOND_TEN[number % 10])
elif (number % 10) > 0:
result.append(FIRST_TEN[number % 10])
return ' '.join(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"
assert checkio(40)=='forty', "Seventh, forty - it is correct"
print('All ok')
Feb. 15, 2014
Comments: