0
what's wrong with this python code???
6 Answers
0
I Found an error if you enter 300 or 400 it will become fourhandred and or threehundreds and
You have to use if to remove the and
+ 1
one more problem is, if we enter 113 than output is "one hundred and ten three"!!!
so please help!!!!
0
No error found?
0
Some thing like this
#convert given numerical to word. minimum=0 maximum=999
words_upto_19=['','ONE','TWO','THREE','FOUR','FIVE','SIX',
'SEVEN','EIGHT','NINE','TEN','ELEVEN','TWELVE','THIRTEEN','FOURTEEN','FIFTEEN','SIXTEEN','SEVENTEEN','EIGHTEEN','NINETEEN']
words_for_tens=['','Ten','TWENTY','THIRTY','FOURTY','FIFTY','SIXTY','SEVENTY','EIGHTY','NINETY']
n=int(input('Enter a number from 0 to 999:'))
output=''
if n==0:
output='ZERO'
elif n<=19:
output=words_upto_19[n]
elif n<=99:
output=words_for_tens[n//10]+" "+words_upto_19[n%10]
elif n<=999:
output = words_upto_19[n//100] +' HUNDRED '
if words_for_tens[(n//10)%10] != '' or words_upto_19[n%10] != '':
output+='AND '+words_for_tens[(n//10)%10]+" "+words_upto_19[n%10]
else:
output='Please enter a value from 0 to 999 only'
print(output)
0
Try this
#convert given numerical to word. minimum=0 maximum=999
words_upto_19=['','ONE','TWO','THREE','FOUR','FIVE','SIX',
'SEVEN','EIGHT','NINE','TEN','ELEVEN','TWELVE','THIRTEEN','FOURTEEN','FIFTEEN','SIXTEEN','SEVENTEEN','EIGHTEEN','NINETEEN']
words_for_tens=['','TEN','TWENTY','THIRTY','FOURTY','FIFTY','SIXTY','SEVENTY','EIGHTY','NINETY']
n=int(input('Enter a number from 0 to 999:'))
output=''
if n==0:
output='ZERO'
elif n<=19:
output=words_upto_19[n]
elif n<=99:
output=words_for_tens[n//10]+" "+words_upto_19[n%10]
elif n<=999:
output = words_upto_19[n//100] +' HUNDRED '
if words_for_tens[(n//10)%10] == 'TEN' and words_upto_19[n%10] != '':
output+='AND '+words_upto_19[n%100]
elif words_for_tens[(n//10)%10] != '' or words_upto_19[n%10] != '':
output+='AND '+words_for_tens[(n//10)%10]+" "+words_upto_19[n%10]
else:
output='Please enter a value from 0 to 999 only'
print(output)
0
Plz run this program on your pc version, sometime the program is not running properly on this app.