7.Reverse , Practice Makes Perfect



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):
    number= len(lizt)
    for n in range(number,0):
        print lizt[number]
        n = n -1


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


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)


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.


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


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