Reverse: While loop


i got this error: Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!

I need help with this. I don't understand why my code doesn't work ): please help thanks!

Replace this line with your code. 
def reverse(text):
    text = str(text)
    index = len(text) + 1
    string = ""
    while index >= 0:
        string = string + text[index]
        index -= 1
    else: return string


Change index = len(text) + 1 to index = len(text) - 1. The max length for your text is always len(text) - 1. You went beyond that with index = len(text) + 1 hence the string index out of range error.


ah.. I see.. thanks so much for the help!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.