Reverse


#1

I need help with this https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/reverse?action=lesson_resume

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?


#2

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


#3

Thanks, I appreciate your help!


#4