Reverse a string


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

It keeps saying that my code returns none, but when I called the function with a string to put it to test it did return more than just none. My code might not be the correct one but I cannot figure out what is wrong when the program only keeps saying it returns none.

Here's the code that I put in:
def reverse(text):
x = str(text)
z = len(x)
p = z-1
word = ""
while p >=0:
word = word + x[p]
p = p -1
print word

print reverse("Python!")

Replace this line with your code.


Hi @oliviajcheng,

Your function does not contain a return statement, therefore it always returns None, even though it does display a result. Instead of ...

    print word

... you should have ...

    return word

That will make the result available to the external print statement that you have here ...

print reverse("Python!")


Hi @appylpye,
thank you so much!