Reverse task


#1


def reverse(x):
    outcome = ""
    if type(x) != str:
        x = str(x)
    for i in range(0, len(x)+1):
        outcome = outcome + x[len(x)-i]
    return outcome

I still count figure out where i'm getting it wrong. I need your help


#3

here:

x[len(x)-i]

you need to subtract one, why? len(x) will start counting at zero, where as string indexes are zero indexed based, so you will need to subtract one to compensate for this difference


#4

Maybe this will help you:

def reverse(text):
length = len(text)
word = []
while (length !=0):
length = length-1
word.append(text[length])
lst = ''.join(word)
return lst
a = reverse('python!')
print a


#6

1.)
an example:

for i in range (0,5): #iterates over 0,1,2,3,4 -- but not 5!!
    pass

2.)
if i is 0 in your first iteration, then x[len(x)-i] is x[len(x)], which is out of range, since the indices begin with 0 and end with len(x)-1


#8