Reverse


#1

def reverse(text):
    reverse_word = ""
    for letter in range(0, len(text)):
        reverse_word += text[len(text)-letter]
    return reverse_word

Sorry if this seems like a silly question. But why doesn't the above code work


Reverse: is text[-] allowed?
#2

if i have the string hello, the length is 5 (counting start at zero) but the o is at index 4, given indexes are zero based. so for the first run of your loop:

text[5-0]

but 5 doesn't exist, the highest index is 4. You will need to do -1 somewhere


#3

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