Reverse problem


#1



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


#2

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!


#3

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


#4

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


#5

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