My code appears to reverse the string, but I am getting an error message shown below. Does anyone know what I should change?
I get the following error message:
Oops, try again. Your function fails on reverse("Python!"). It returns "!nohtyPcba!nohtyP" when it should return "!nohtyP".
I was expecting this to work, and the output window does show that the string gets reversed. This is the output:
ans= def reverse(text): pos = -1 for i in range(len(text)): ans.append(text[pos]) pos = pos -1 return ''.join(ans) print reverse("Python!")