I’ve yet to run into a wall during the entire Python course like I have with this particular exercise. After spending far too long on it, I allowed Codecademy to provide its own solution to the problem (listed below).
def reverse(text): word = "" l = len(text) - 1 while l >= 0: word = word + text[l] l -= 1 return word
I would like to understand the given solution better.
For example, in this line:
l = len(text) - 1
What’s going on with the " - 1 " at the end of the line? Why is this necessary?