I want to write a function, which will accept parameter and it will print with a condition (It's output will depend on the input). My program is giving key error. I am looking for an output like:
This number is less than 0 and it's spelling is one hundred
thirteen
and my code is:
def word(num):
d1= {0:'Zero',1:'One',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:'Ninteen',20:'Twenty',30:'Thirty',40:'Fourty',50:'Fifty',60:'Sixty',70:'Seventy',80:'Eighty',90:'Ninty'}
if (num<20):
return d1[num]
if (num<100):
if num % 10 == 0:
return d1[num]
else:
return d1[num // 10 * 10] + ' ' + d1[num % 10]
if (num < 0):
return "This number is less than 0 and it's spelling is" + word(num)
print (word(- 100))
print (word(13))
Aucun commentaire:
Enregistrer un commentaire