Reverse


#1



My code is not working as below, but I can't find the problem, is it because I use range?


def reverse(text):
    str = ""
    for i in range(len(text)-1,1):
        str += text[i]
    return str


#2

maybe take a look at the documentation about range:

https://docs.python.org/2/library/functions.html#range

range can take 3 arguments (start, stop, step) see which ones you need in this exercise


#3

I'm using range(start,stop)


#4

but if the start value is higher then the stop value, you can't use the default of +1 steps. That doesn't work, you will need the third argument


#5

You cannot use str as a variable. str is a reserved word. change it to string or another name and make sure you are looping through the entire length of the string. Use print statements to print out value of text[i] to make sure its printing the correct values.


#6

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