Returns the raw input backwards (which is why I don't understand what's wrong), but then returns "None" underneath it.

It seems to work, other than the "none," but Code Academy error message says: "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"

word = raw_input("input word\n")

def reverse(text):
    backwards = ""
    my_index = len(word)
    for letter in range (0, my_index):
        backwards = backwards +text[-letter-1]
    return backwards
a = reverse(word)         
print a

Thanks. I'm new to this. I know there are other posts and I've read most of them. My code seemed to be working most of the way, even if inefficient, which is why I continued with it so it was a problem solving exercise instead of copying and pasting. I'm sure it can be done better, but it looks more or less like it's working this way. Any and all help is appreciated.



my_index = len(word)

you get length of word, why? You supply word as argument at function call, so you can get the length of text, this way, your function works for multiply strings


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.