7/15 How do I reverse a raw_input?


#1

I've figured out how to create a reverse function when the parameter exists. However, I cannot seem to get it to work when the parameter takes the value of a raw_input.

Everything appears as expected on the console, but I keep receiving the error message:
Your function fails on reverse("Python!"). It returns "" when it should return "!nohtyP".

Please advise! Your help is greatly appreciated. :smile:

 def reverse(x):
        x = raw_input("Give me a word to reverse: ")
        reverse = []
        word = len(x)-1
        for letter in range(-1,word):    
            reverse.append(x[word]) 
            word -= 1
        return "".join(reverse)
        
    print reverse("x")

#2

I'm not a huge Python guru, but doesn't this line seem strange?

return "".join(reverse) #Returning an empty string no matter the input.

Perhaps printing x prior to the return statement.


#3

I'm not sure if I'm using it correctly, but what that does is combines the characters from my dictionary reverse = [].

Essentially it takes away the any special characters like "," and "[]" and forms a normal looking string/word.


#4

This code is correct, but I guess it's not working in 7/15 because codecademy isn't expecting you to use raw_input. I put your code into a blank exercise (1/15 "Practice Practice Practice!") and it worked perfectly. However, I would recommend removing the parameter x since the actual input is taken from raw_input.