IndexError: string index out of range keeps coming up

IndexError: string index out of range keeps coming up

我正在学习应用程序 Jar 模块,所以我决定制作一个编码器,但我一直收到此错误并且我不明白它的含义。我在这里查过它,它谈到了索引,但我没有得到任何我不认为的。我的代码在下面,我希望你能帮忙。 This is the error

请注意,Python 中的字符串索引从 0(第一个符号的索引)开始,以 len(string) - 1(最后一个符号的索引)结束。在您的代码中,您有 counter <= numLetters,因此在最大索引为 counter - 1 时尝试使用 counter 索引访问符号时出错,请改用 counter < numLetters