Practice Makes Perfect-Reverse


Can someone please explain why I'm getting Oops, try again. Your function fails on reverse("Python!"). It returns "cba!nohtyP" when it should return "!nohtyP".

def reverse(text):
    for num in range(0,int(len(text))):
    return "".join(_new)


The problem is the result of not using a locally defined list. Every run of the program continues to add to the list. Define your list inside the function and it should work.


will work since x is defined, and it is an integer already (len() returns an int).

text[x - 1]

is sufficient.


The more pythonic way is text[::-1]


I agree; however, that isn't my point specifically, but simplification of the OP code.