7. reverse


#1



https://www.codecademy.com/en/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".


This seems to work perfectly fine when I execute the code in PyCharm. For whatever reason, the lesson doesn't seem to like the submission. Any thoughts? I've read other posts and gotten other solutions to work, but this seemed more intuitive to me. Thanks in advance for any feedback.


def reverse(text):
    backwards = []
    for letter in text:
        backwards.insert(0,letter)
    end = ""
    for item in backwards:
        end += item
    print end


#2

your function prints the reversed string, it doesn't return the reversed string


#3

Sorry for wasting your time... Little things like that don't register sometimes after working through lots of these problems.

Thanks for your help!


#4

no problem. Exactly, so then you can use a little help :slight_smile:


#5

Can someone explain to me piece by piece what is happening? I don't feel prepared at all to do this.


#6

well, isn't that part of the challenge to maximize the learning effect?

we could use range() for this, given range also allows to loop from right to left, if we do this we can append to list/string, causing the string to reverse


#7

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