I'm having trouble getting my code to run. I'm getting a 'string index out of range' error. Any ideas? I'm simply setting a variable equal to the length of the string and using that to store the letters counting back to the start of the string.

def reverse(text):
    length = len(text)
    rev = []
    while length > 0:
        char = text[length]
        length -= 1
    result = "".join(rev)
    print result
    return result


char = text[length]

The length variable holds the length of the text.
But index starts from 0 so there is no value for text[length]


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