The range(-1, 0, -1)
is empty. A range can not work with the fact that -1
will result in the last element, since it does not know the length of the collection (here a string).
So if we convert the range(..)
to a list, we get:
>>> list(range(-1, 0, -1))
[]
You thus need to start with len(string)-1
, furthermore since the second parameter is exclusive, this should be -1
. For example:
>>> string = 'foobar'
>>> list(range(len(string)-1, -1, -1))
[5, 4, 3, 2, 1, 0]
So in your case we can use this like:
for i in range(len(string)-1, -1, -1):
print(string[i],end="")
An aternative is to use reversed(..)
, or by slcing the string:
for c in reversed(string):
print(c, end='')
Note that you better first generate the full string, so for example:
print(string[::-1])
or an alternative (but less performant):
print(''.join(reversed(string))