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

can somebody help me please? the hint said to try and loop through the text from the 1st letter to last. I tried doing that, but I obviously have something wrong here.(the function doesn't even return anything at all, never mind the wrong output).
any help is appreciated. thanx.:slight_smile:

def reverse(text):
    for letter in range(len(text), (len(text) - len(text)-1)):
        return letter


The loop is not running else there would be one letter returned, not None.

I don't think you want to be returning letter from inside the loop, do you?

Some sort of variable should be growing out of the loop, which when the loop is complete will be returned.


I edited my code to this and it worked! Thanx for your help!:slight_smile:

def reverse(text):
    rtext = ''
    index = len(text)
    for letter in text:
        index -= 1
        rtext = rtext + text[index]
    return rtext


I had this:

def reverse(text):
rtext = ""
x = 0
for letter in text:
x += 1
rtext = rtext + text[len(text)-x]
return rtext

but it didn't work. It doesn't seem so different from yours though.
Do you know why it doesn't work?


Incrementing too soon. Do it after the next line.


thanks a lot! it worked :slight_smile:


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