def reverse(text): i = len(text) final = "" while i >= 0: final += text[i] i -= 1 else: return final.
well, strings are zero indexed based (counting starts at one), but
len() start counting at one. So for example
hello would have a length of 5 and the following indexes: 0, 1, 2, 3 and 4.
you use length in the first iteration of your loop, but this out of range for the reason i just explained above
thank you for your explanation, and i set:
i = len(x)-1
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.