Search code examples
pythonappjar

IndexError: string index out of range keeps coming up


I am learning the app Jar module so I decided to make an encoder but I keep getting this error and I don't get what it means. I have looked it up on here and it talks about indexes but I haven't got any I don't think. My code is below an I hope you can help. This is the error


Solution

  • Note that indexes in string in Python starts from 0 (index of the first symbol) and ends with len(string) - 1 (index of last symbol). In your code, you have counter <= numLetters, so you have error trying access symbol with counter index while the maximum index is counter - 1, use counter < numLetters instead.