7/15 what s wrong with my code?


#1

def reverse(text):
a=[]
i=len(text)-1

print a
while i>=0:

    print i
    a.append(text[i])
    i=i-1
    print a

return a

reverse("abcd")


#2

@pythonmaster1031 here is your code corrected with comments on what changed

def reverse(text):
    a=[]
    i=len(text)-1
    #trace statement
    print a
    while i>=0:
        #trace statement
        print i
        a.append(text[i])
        i=i-1
    #trace statement
    print a
    #if you just return a you will get a list
    #you need to join all the elements in to a single string
    return "".join(a)
    
print reverse("abcd")

#3

thank u so much rydan!!!! :joy: :joy:


#4

can you correct and improve mine plz

def reverse(text):

word = ""
for i in reverse(text):
    word = text[i]
return word