Reverse


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096#


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


can u show me what is wrong in my code plz?


def reverse(text):
    for string in text:
        i = len(str(text))-1
        new_text= text[i]
        print new_text
        i -=1
        
        
reverse("abcd")


#2

This is because there is no return statement.

There are other issues that need to be resolved. text is already a string, for starters.

A more descriptive variable would be, letter, or, char, since we are iterating over a text string one letter at a time.

for letter in text:

This line conflicts with,

As mentioned, this line,

should not be there. Let the loop complete then return the new text.

Short of writing a solution for you, the best thing to do is re-think this problem and do it over from scratch.


#3

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