Help with Reverse


#1



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

The code keeps giving none with this error message:

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


What is happening here? I ran out of ideas what to change or what might be the problem?


def reverse(text):
    reversed_text = []
    for letter in text:
        count = 1
        letter = text[len(text) - count]
        reversed_text.append(letter)
        count += 1    
    reverse_string = ''.join(reversed_text)   
    print reverse_string


#2

You're not returning anything :slight_smile:
You're only printing.


#3

I tried replacing the print with return and now I'm getting this:

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

Argghh :expressionless:
Any advice?


#4

Here. Move this count outside of the loop. Or else every time you loop, your count gets reset back to 1 so count += 1 isn't really doing anything. Hence why you get "!!!!!!!" instead because count was stuck at 1.


#5

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