the code above is correct, cause I changed the line 3 into "n = len(text) - 1" and line 4 into "while n > -1".
The question is what if I delete both of "-1" in these two lines? I mean, line 3: "n = len(text)", line 4: "while n > 0", Because I think it is equal to the correct one. I tried this one, it cannot work out, but I don't know why.
I want to know why the change I thought can not equal to the correct one? and why should "n = len(text)" subtract 1?
thanks for your answering and time!
def reverse(text): result =  n = len(text) - 1 while n > -1: result.append(text[n]) n = n - 1 return ("".join(result))