Python verbose function

Write a function called verbose that, given an integer less than 100000, returns the name of the integer in English. As an example, verbose(123456) should return one hundred twenty-three thousand, four hundred fifty-six.

def verbose(n):
    d = {1:'one', 0:'', 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'}


   
if n < 100000:
        t =
str(n)
       
if len(t) == 1:
            
print(d[int(t)])
       
if len(t) == 2 and 9 < int(t) < 20:
           
print(d[int(t)])
       
if len(t) == 2 and int(t) > 19:
            first =
int(t[:1])*10
           
second = int(t[1:2])
           
print(d[int(first)],'-', d[int(second)], sep='')
       
if len(t) == 3:
            first =
int(t[:1])
            second =
int(t[1:2]) * 10
           
third = int(t[2:3])
           
print(d[int(first)],' hundred ',d[int(second)],'-',d[int(third)], sep='')
       
if len(t) == 4:
            first =
int(t[:1])
            second =
int(t[1:2])
            third =
int(t[2:3]) * 10
           
fourt = int(t[3:4])
           
print(d[int(first)],' thousend, ',d[int(second)],' hundred ',d[int(third)],'-',d[int(fourt)], sep='')
       
if len(t) == 5 and 9999 < int(t) < 20000:
            first =
int(t[:2])
            second =
int(t[2:3])
            third =
int(t[3:4]) * 10
           
fourt = int(t[4:5])
           
print(d[int(first)],' thousend, ',d[int(second)],' hundred ',d[int(third)],'-',d[int(fourt)], sep='')
       
if len(t) == 5 and int(t) > 20000:
            first =
int(t[:1]) * 10
           
second = int(t[1:2])
            third =
int(t[2:3])
            fourt =
int(t[3:4]) * 10
           
five = int(t[4:5])
           
print(d[int(first)],'-', d[int(second)],' thousend, ' ,d[int(third)], ' hundred ', d[int(fourt)],'-',d[int(five)], sep='')

verbose(
65689)

SOLUTION:

sixty-five thousend, six hundred eighty-nine

Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python Accounting