7. reverse


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

Replace this line with your code. 
def reverse(text):
    for x in text:
        x = str(text[-1])
        return x
    return text


this code has a few problems:

x is just a variable which will hold each letter in turn:

def reverse(text):
    for x in text:
       print x

so it will never persist. You could make a list/string outside the loop to append letters to? depending on the approach you want to take

a function ends the moment a return keyword is reached, in your case in the first run of the loop


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