Reverse


#1



reverse


If I run this in pycharm I don't get any errors but here it says "Oops, try again. Did you create a function called reverse? Your code threw a "local variable 'x' referenced before assignment" error." What is wrong?


x = 0
def reverse(text):
    letter = range(len(text)-x)
    print letter
    x += 1


#2

the exercise calls the function with different strings to verify your function works correctly.

But only your function, not the whole script, so then x is not defined, place x=0 inside the function


#3

Ok thanks, I just realised I did something that makes no sense


#4

yea, because you need to return the reversed string. Can you figure it out from here or do you need more help?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.