Reversing The String - String Out of Index Range


#1


The code I have written to reverse an entered string shows an error.

It returns that the string is out of index range, while I have taken all care to keep all the variables well in the index range of the length of the entered string. Here's the code:

def reverse(text):
    revstr = "";
    strtext = str(text);
    i = len(strtext);
    j = i-1;
    while j>=0:
        for k in range(i-1):
            text[j]=revstr[k];
            j-=1;
    return revstr;

#2

Check which indexes you use for what value (use print)


#3

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