Reverse problem


I am stuck at "reverse" excersise and have no idea why my code fails.

But the most bizzare part of the problem is that error message says that my code must return "!nohtyP", but it returns "!nohtyP". Genius.
Can someone explain where exactly have I messed it up?

def reverse(text):
    rev = ' '
    i = 0
    for letters in text:
        rev += text[(len(text)- 1 - i)]
        i += 1
    return rev


I do think you copied by hand what the submission test claims your function returns. Because it doesn't return that. Look closer.

You expect your function to return a particular string, and instead of carefully reading/copying what it said was your result, you wrote what you think it returns!


Indeed! I had a space in rev variable when it should be completely empty. Thank you!


There should be no space between single quotes while initializing rev variable.


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