Throws a "string index out of range" error


#1

My code is very pretty much the same, but it throws a "string index out of range" error.

def reverse(text):
i=len(text)
x=""
while i>=0:
return x.join(text[i])
i-=1
return x


7. reverse
#2

Got it.

def reverse(text):
....x = ""
....i = len(text)
....while i > 0:
........i -= 1
........x += text[i]
....return x


#3

this worked for me
def reverse(text):
if type(text) == str:
newtext = ""
for i in text:
newtext = i + newtext
return newtext
else:
return "Gimme a text only string"