7/15 Reverse


#1



7/15 Reverse

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

Can't tell why it's wrong. I did a call on the function and it came out correct


#Lists
letters=[]
rletters=[]

#function
def reverse(text):
    #def
    z=len(text)-1

    #creation of a list to seperate letters
    for x in text:
        letters.append(x)
    #show list    
    print letters
  
    #reversing the letters and appending to a new list
    for y in range(z+1):
        rletters.append(letters[z])
        z-=1
    #print reversed list
    print rletters
    
    for k in rletters:
        a= "".join(rletters)
        print a
        return a


#2

the exercise runs many different strings to test your code, in order to make this work correctly you need to put this:

letters=[]
rletters=[]

inside your function. Because it is now outside your function, it never makes the list empty again, which can make things messy


#4

<3 Thank you so much! moving it into the definition works. I'll remember that for future exercises :slight_smile