7.Reverse


#1

In Practice Makes Perfect Reverse, I made this code that I think should work. When I change the "return" in my code to "print," the program changes "Python!" to "!nohtyP," as it should. When my code runs as shown, it returns the error message:

Oops, try again. Your function fails on reverse("Python!"). It returns "!nohtyPcba!nohtyP" when it should return "!nohtyP".


back = []
def reverse(text):
    index = len(text)-1
    while index > -1:
        back.append(text[index])
        index -= 1
    return "".join(back)

#2

back = []

back should be inside your function, since the exercise tests your function, since back is outside of your function, there might remain leftovers from other function calls


#3

Thank you so much! It works now!