Python: string index out of range


#1

I am piece meal working through the reverse word exercise. I am starting with just breaking down the string and counting the characters in each string and printing each of those characters.

(You will see #greyed out code for the next steps). However, I keep getting one error that I do not know how to correct: IndexError: string index out of range

The ranges are quite important because they determine the placement of the letters in the next step.

The code is here:

thanks,

Eric


#2

you go wrong here:

while count <= len(string)

lets say the string has a length of 5, the highest index is 4 (strings are zero indexed based) so you don’t want the value equal to the length


#3

Perfect explanation! Thank you.