7/15 Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!


#1

def reverse(text):

demo=""
ln=len(text) - 1
for i in range(0,ln):
    demo[i] = text[ln - i]
    print demo[i]

This function throws error: Oops, try again. Your code looks a bit off--it threw a "string index out of range" error. Check the Hint if you need help!


#2

You don't need all that extra stuff,

Example:

def reverse(text):
    return ''.join([text[-(index + 1)] for index, letter in enumerate(text)])

While the built-ins are better for this stuff but the exercise is to build your own.

This can also be expresses as a for loop,

def reverse(text):
    new_text = []
    for index, letter in enumerate(text):
        new_text.append(text[-(index + 1)])
    return ''.join(new_text)

#3

this simple way works too

def reverse(text):
rev = ""
for char in text:
rev = char + rev
return rev

each character is added in turn to the start of rev.