I need help with this

This is what I wrote:

  def reverse(text):
  a = len(text)
  b = ''
  while a >= 0:
    b += text[a]
    a -= 1
  return b

I keep getting this error message: Your code looks a bit off–it threw a “string index out of range” error.

Where is the problem?


strings are zero indexed based, while len() start counting at 1. So if we have "hello" the length is 5, while the highest index is 4, that is why you get an index error


Thanks, I appreciate your help!