Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Speech Module by UFO665
firstTen = {"1": "one", "2": "two", "3": "three", "4": "four", "5": "five",
"6": "six", "7": "seven", "8": "eight", "9": "nine"}
secondTen = {"10": "ten", "11": "eleven", "12": "twelve", "13": "thirteen",
"14": "fourteen", "15": "fifteen", "16": "sixteen", "17": "seventeen",
"18": "eighteen", "19": "nineteen"}
other = {"2": "twenty", "3": "thirty", "4": "forty", "5": "fifty", "6": "sixty",
"7": "seventy", "8": "eighty", "9": "ninety"}
def firstHundred(number):
sNumber = str(number)
if number < 10:
return firstTen[sNumber]
elif number < 20:
return secondTen[sNumber]
else:
return " ".join([other[sNumber[0]], firstTen.get(sNumber[1], "")]) if sNumber[1] != "0" else other[sNumber[0]]
def checkio(number):
sNumber = str(number)
if number < 100:
return firstHundred(number)
elif sNumber[1:] != "00":
return " ".join([firstTen[sNumber[0]], "hundred", firstHundred(int(sNumber[1:]))])
else:
return " ".join([firstTen[sNumber[0]], "hundred"])
Dec. 5, 2015