Reversing The String - String Out of Index Range


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):
    return revstr;


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


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