Reverse


#1



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


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


It prints out the string backwards so I don't know why it won't let me move on? is it running for too long?
Thanks for the help!


def reverse(text):
    x = ""
    for c in text:
        x += c
    a = len(x)
    total = a - 1
    while total >= 0:
        print x[total],
        total -= 1 
reverse("Python!")


#2

You are printing when you should be returning the reversed statement.


#3

WOW...
Thank You!:pizza:


#4

To better understand how the test code decides whether you pass or fail the checkpoint, it is helpful to view the actual test code. This bookmarklet can help with that.


#5

Maybe try something like this.

def reverse(text):
    x = ""
    a = len(text)
    total = a - 1
    while total >= 0:
        x += str(text[total],)
        total -= 1 
    print x
    return x
        
reverse("Python!")

#6

What I ended up doing:

def reverse(text):
x = ""
for c in text:
x += c
a = len(x)
total = a - 1
b = ""
while total >= 0:
b += x[total]
total -= 1
return b
print b

reverse("Python!")


#7

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