can anyone explain why it says i through a "local variable 'e' referenced before assignment"

def reverse(text):
    x = str(text)
    y = len(x)
    z = y-1
    word = ""
    while e > 0:
        word += text[e]
        e -= 1
    return word



while e > 0:

you use e, but you haven't defined it yet, where do you think you created e?


i don't know i posted my code up there in it's entirety


well, you can't use variables (like you do in your loop condition) before you defined them. Sure you didn't mean to use z? it contains the length of text minus one, which would be perfect


thx but now it says Your function fails on reverse("Python!"). It returns "!nohty" when it should return "!nohtyP". after i replaced all the e's with z's


well, now your loop condition is this:

while z > 0:

the problem is, strings are zero indexed based. so the p of python is index 0, your loop ends at index 1. So you need to slightly modify your loop condition


Also: You don't need "x = str(text)."
I tried your code, with the correction to the loop condition, and "y = len(text)" works just as fine.

It's already a string that you recieve, as stated in the instructions.


thx that solved the problem