7 Reverse


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:


def reverse(text):
    pos = -1
    for i in range(len(text)):
        pos = pos -1
    return ''.join(ans)
print reverse("Python!")


place this:


inside your function

the exercise calls the function multiply times for validation, if ans is not inside the function, the list doesn't get reset


Thank you. That fixes it. :grinning: