Reverse help


#1



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


I got the error message: Your function fails on reverse("Python!"). It returns "['P']" when it should return "!nohtyP".


I expected the program to take a string and place each character into a list, then iterate backwards through the list, printing each character as it went.


def reverse(x):
    char = []
    for c in x:
        char.append(c)
    for i in char[len(char):0:-1]:
        print i
    print char[0]


#2

you need to return the reversed string

to get from list to string at the end, you can use .join()


#3

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