+ 1
Why this code doesn't work....?
p=input() flag=0 for j in p: if j=='1': flag=1 continue elif j=='0': if flag==1: print('ten',end='') flag=0 else: print('zero',end='') elif j=='2': print('two',end='') elif j=='3': print('three',end='') elif j=='4': print('four',end='') elif j=='5': print ('five',end='') elif j=='6': print('six',end='') elif j=='7': print('seven',end='') elif j=='8': print('eight',end='') elif j=='9': print('nine',end='') elif flag=='1': print('one',end='') flag=0 else: print(j,end='')
5 Answers
+ 2
What is the expected output u want to help u ?
+ 2
You need to decide whether your flag is an integer (flag == 1) or a string (flag == '1'). You can't use both in the same code.
+ 1
It skipping to convert 1 to one. Missing case which have input 1. Check your logic again when j=='1', and it never going true in 'elif flag=='1' : need a change here.
instead of print in every if block, use a string and finally print string . else use replace function..
and also you can simplifies this code lot of ways.. even to 1 liner.
but still, I think ,better to continue first complete code to pass all cases. next try to simplify.. just telling..
edit:
oh. yes ..
change '1' to 1 will works fine . and add a space in
elif flag==1:
print('one',end=' ')
flag=0
0
Explain your question... also use appropriate tag
0
I think so it is no numerals code coach