+ 1
Why This code gives an error " String index out of range " ?
print (" input string") str1=input() count=0 for i in range(0,len(str1)): if(ord(str1[i]+1 == ord(str1[i+1])): count +=1 else: count =0 print(count)
1 Antwort
+ 1
Your loop goes until len(str1).
So eventually str1[i] will be the last letter.
But even then you try to access str1[i+1] which is one slot beyond your string.