Reverse() Problem


#1



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


The message error say:
Your function fails on reverse("Python!"). It returns "None" when it should return "!nohtyP".


I try the same code on the Idle Python and works. Is not the first time that happens. In other exercises happens the same.
My apologizes, my english is really bad, I am from Uruguay.


def reverse(text):
    con = len(text) - 1
    f = []
    u = con + 1
    for x in text:
        f.append(x)
    while u != 0:
        b = f[con]
        print(b)
        con = con - 1
        u = u - 1
    return


#2

last line:

return

you should return the reversed string


#3

That code return one character in each line. Now I modify with this code below . This returns me all in one line.
I solved, close this discuss. Thanks for the help.

def reverse(text):

con = len(text) - 1
f = []
tot = ''
u = con + 1

for x in text:
    f.append(x)


while u != 0:
    a = f[con]
    tot = tot + a
    u -= 1
    con -= 1
    
    return tot

#4

as you discovered, one character a line is not enough. You need to construct a string which contains the reversed string, good you figured it out :slight_smile:


#5

Thanks so much. Excellent tutorial. :thumbsup:


#6