Problem with the reverse excercise


def reverse(text):
for i in range(len(text)):
print list_i

this is my code for the reverse exercise but its showing a "string index out of range" error, can someone help me with this please


lets say i want to reverse the following string:


agree that the length is 5, and the indexes are: 0, 1, 2, 3 and 4?

so, for the first run of the loop, i is zero and the length is 5, so:


we don't have an index 5, the highest index 4, that is why you get an error


Thanks alot , its a stupid error


no, its a difficult one. Hope you are now able to solve the problem yourself :slight_smile: , now that you know what the problem is. Otherwise, post an updated version of your code


Thanks alot , i was able to solve it


Nicely done :slight_smile: You did most of the work and thinking, i just had to give you a little nudge in the right direction :slight_smile:


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