Reverse


#1



I am stuck at the reverse practice.

This is my code, which I think will work but actually it turns out when the input is "python!", the output is "!!!" instead of the reverse.

Replace this line with your code. 
text = raw_input('Put the word: ')

def reverse(text):
    a = ''
    for c in (len(text) - 1, -1, -1):
        a += text[c]
    return a
<What do you expect to happen instead?>


#2

Look at what you are looping through

print (len(text) - 1, -1, -1)

If you don't know what happens, find out! Have a look.


#3

hey!!!where your "range"?


#4

Python slices like this (start:end:step)

In your case: (len(text) - 1, -1, -1)
start: len(text)-1 is"!"
end: -1 which is equivalent to len(text)-1, and this represents "!"
step: -1 which represents exclude last index, this will exclude last char i.e. "!"

This always gives an empty list, since the start and end indices are the same and the end index is exclusive.