7. reverse


#1




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
        text.remove(x)
    return text


#2

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
reverse("Python!");

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


#3

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