7. reverse


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096#


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


why is it not working?


def reverse(text):
    n = len(text) - 1
    total = " "
    while n >= 0:
        total += text[n]
        n -= 1
    return total

print reverse("Python!")


#2

because there is a space in the beginining of the reversed string


#3

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