0
Where is mistake?
Where is mistake? a=str(input()) n=len(a) for i in range (n): if a[i] ==1: a[i]="one" if a[i]==2: a[i]="two" if a[i]==3: a[i]="three" if a[i]==4: a[i]="four" if a[i]==5: a[i]="five" if a[i]==6: a[i]="six" if a[i]==7: a[i]="seven" if a[i]==8: a[i]="eight" if a[i]==9: a[i]="nine" if a[i]==10: a[i]="ten" if a[i]==0: a[i]="zero" print (a) input: 1 is the loneliest number output: 1 is the loneliest number there should be "one is the loneliest number"
3 odpowiedzi
+ 2
a is a string. So a[i] can only be equal to '1', '2'..... and not 1, 2.......
i.e. a[i] cannot be an integer, so compare it with a string.
+ 1
Also even after you correct that, the program is going to cause an error as you cannot change an index of a string.
Instead of a[i] = "one", do
a = a.replace(" 1", "one")
for all the digits
0
thank you!!