Lesson 7


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1

My code prints the right input ("!nohtyP), but for some reason the return message reads: "Oops, try again. Your function fails on reverse("Python!"). It returns "!nohtyPcba!nohtyP" when it should return "!nohtyP"." Why is the return like that and how do I fix it?


Replace this line with your code. 
lst = []


def reverse(txt):
    reverse_text = ""
    for l in txt:
        lst.append(l)
    n = len(lst) - 1
    while n >= 0:
        reverse_text += lst[n]
        n -= 1
    return reverse_text
    
print reverse("Python!")


#2

@mattisse,
Maybe you should initialize your lst variable

def reverse(txt):
    reverse_text = ""
    lst = []
    for l in txt:
        lst.append(l)
    n = len(lst) - 1
    while n >= 0:
        reverse_text += lst[n]
        n -= 1
    return reverse_text
    
print reverse("Python!")

#3

Ah that was perfect, thank you! Why does creating a global empty list create such a weird return? With the abc and everything.


#4

@mattisse,
I don't understand
what is it you want to state....