Practice Makes Perfect: 7. Reverse


#1

Why is this code wrong?

def reverse(text):
    rau = len(text)
    while rau > 0:
        print text[rau - 1]
        rau -= 1

When I reverse("Python!") program prints" !
n
o
h
t
y
P"
But notifications says "Oops, try again. Your function fails on reverse("Python!"). It returns "None" when it should return "!nohtyP"."


#2

but in the error message is a important word: returns

the exercise expects you to use the return keyword


#3

Thank you, but than: "Oops, try again. Your function fails on reverse("Python!"). It returns "!" when it should return "!nohtyP"."
I don't know what is wrong with code :disappointed_relieved:


#4

you don't store the result of the reverse anywhere, you should. (a list, or a string)


#5

It says that because the ! is on a different line than the other letters, but if you put a comma after the return ... statement, it will say it returns "('i')"


#6

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