Reverse: While loop


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096

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


#2

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.


#3

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


#4

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