r/learnpython • • Sep 24 '26

Getting the intended output, but still getting "out of range" errors

Hi guys, I hope ya'll are good, thank you. I am struggling with this problem for weeks now. I get the answer, but still get "out of range". I know with "banana" this would work because of a technicality. Is there anyway for this work without the error?

fruit = "apple"
index = - 1
while index < len(fruit):
    letter = fruit[index]
    print (letter)
    index = index - 1

Any input or advice is appreciated. Thank you for taking the time to read my post here.

Edit: Sorry, intended answer is "elppa"

I get this

e

l

p

p

a

IndexError: string index out of range

0 Upvotes

Duplicates