NumToWord
#@roshanb79
def convToWord(num):
sflw=[]
lastc=''
uth=""
for i in reversed(num):
if len(sflw)==0: #checking is list is empty
sflw.append(numwords1[i])
uth+="unit:"+i
elif len(sflw)==1:
uth+=",tens:"+i
if i=="0":
sflw.append("")
elif lastc=="0":
sflw[0]=""
sflw.append(numwords3[i])
elif i=="1":
sflw.pop(0)
sflw.append(numwords2[lastc])
else:
sflw.append(numwords3[i])
elif len(sflw)==2:
uth+=",hundred:"+i
if i=="0":
sflw.append("")
else:
if sflw[0]=="" and sflw[1]=="":
sflw.append(numwords1[i]+" Hundred")
else:
sflw.append(numwords1[i]+" Hundred And ")
else:
print("Give Number between 0-999")
lastc=i
finalword=""
for word in reversed(sflw):
finalword+=word
print(finalword)
print(uth)
numwords1={"0":"","1":"one","2":"two","3":"three","4":"four","5":"five","6":"six","7":"seven","8":"eight","9":"nine"}
numwords2={"1":"eleven","2":"twelve","3":"thirteen","4":"fourteen","5":"fifteen","6":"sixteen","7":"seventeen","8":"eighteen","9":"nineteen"}
numwords3={"1":"ten","2":"twenty","3":"thirty","4":"fourty","5":"fifty","6":"sixty","7":"seventy","8":"eighty","9":"ninety"}
while True:
usrinp=input("Enter Number:")
convToWord(usrinp)
Comments
Post a Comment