why my code doesn't run .
def reverse(text):
retxt = ""
for a in range(len(text) , 0 , -1):
retxt += text[a]
print retxt
the error is ,
Traceback (most recent call last):
File "python", line 6, in
File "python", line 4, in reverse
IndexError: string index out of range


lets say we want to reverse "hello", then the length is 5 but strings are zero indexed based, so the indexes are: 0, 1, 2, 3 and 4

so you need to subtract one from the length to compensate for this counting difference, otherwise you get an index error as you experienced


thak u for helping me i have finished