7.Reverse , Practice Makes Perfect


#1



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


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


I want to print from the last letter to the first


def reverse (str):
    lizt=[str]
    number= len(lizt)
    for n in range(number,0):
        print lizt[number]
        n = n -1


#2

I kind of need help here, i know it is not a big deal but im stuck at it, thank you for taking the time to read my code


#3

range() can have 3 arguments: start, stop and step

by default steps are +1:

range(0, 5, 1)

if you want negative steps, you have to specify this:

range(5, 0, -1)

#4

I have the same problem but still unable get any result.

def reverse(text):
    if text==str:
        x = [text]
        for i in range(len(x), 0, -1):
            return x[i]

that's my code.


Reverse!
#5

a function ends the moment a return keyword is reached

so you want to add/append characters to a string/list in the loop, and then return the reversed string after the loop

also, this condition:

if text==str:

is false, if you want this condition (which you don't need) check whether text is of type() string


#6

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