HW6 #4

mail@pastecode.io avatar
unknown
python
2 years ago
2.1 kB
13
Indexable
Never
num = input("Enter a number: ")
pron = ""

if 0 < int(num) < 1000:
    if int(num) >= 100:
        match num[0]:
            case "1" : pron += " one hundred"
            case "2" : pron += " two hundred"
            case "3" : pron += " three hundred"
            case "4" : pron += " four hundred"
            case "5" : pron += " five hundred"
            case "6" : pron += " six hundred" 
            case "7" : pron += " seven hundred"
            case "8" : pron += " eight hundred"
            case "9" : pron += " nine hundred" 
        num = int(num) - int(num[0])*100
        
        if int(num) > 0:
            pron += " and"

    if 10 <= int(num) < 20:
        match str(num)[1]:
            case "0" : pron += " ten"
            case "1" : pron += " eleven"
            case "2" : pron += " twelve"
            case "3" : pron += " thirteen"
            case "4" : pron += " fourteen"
            case "5" : pron += " fiveteen"
            case "6" : pron += " sixteen" 
            case "7" : pron += " seventeen"
            case "8" : pron += " eighteen"
            case "9" : pron += " nineteen"
    elif 20 <= int(num) < 100:
        match str(num)[0]:
            case "0" : pron += ""
            case "2" : pron += " twenty-"
            case "3" : pron += " thirty-"
            case "4" : pron += " forty-"
            case "5" : pron += " fifty-"
            case "6" : pron += " sixty-" 
            case "7" : pron += " seventy-"
            case "8" : pron += " eighty-"
            case "9" : pron += " ninety-"
        match str(num)[1]:
            case "0" : pron += ""
            case "1" : pron += "one"
            case "2" : pron += "two"
            case "3" : pron += "three"
            case "4" : pron += "four"
            case "5" : pron += "five"
            case "6" : pron += "six" 
            case "7" : pron += "seven"
            case "8" : pron += "eight"
            case "9" : pron += "nine"
elif int(num) == 0:
    pron = "zero"
else:
    pron = "I don't know"

print(pron)