7. reverse


#1

It doesn't seem to iterate...

n = "apple"
def reverse(text):
    index = len(text)
    for i in range(index):
        new = ""
        i = i+1
        new = new + text[index-i]
        return new
print reverse(n)


#2

this line:

new = ""

i would pace it before the loop, otherwise all the progress you make gets erased, this will set new to an empty string (each run of the loop)

a function ends the moment a return keyword is reached, this currently happens in the first iteration of your loop, change the indent of return so the whole loop can run


#3

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