Reverse


#1


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

I keep getting "Oops, try again. Your function fails on reverse("Python!"). It returns "!" when it should return "!nohtyP". I don't understand why the while statement breaks after returning the first item that is stored in list x.


Replace this line with your code. 
def reverse(text):
    lists = []
    for key in text:
        lists.append(key)
    
    a = len(text)
    while a > 0:
        a -= 1
        x = []
        x.append(lists[a])
        return "".join(x)


#2

Initialize your empty list outside of the loop.


#3

Thanks You!! It works now.


#4

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