7/15 Why does it work in python 2.7.10 shell and not here?


#1

I don't understand , when i give this code in python 2.7.10 shell it worked but it is not working here . What is the problem

def reverse(text):
x = len(text)-1
for i in text:
y = text[x]
x = x-1
print y


#2

It want's you to print the whole word not letter by letter,

Your Code:

    x = len(text)-1
    for i in text:
        y = text[x]
        x = x-1
        print y

Fixed Code:

def reverse(text):
    x = []
    for index, letter in enumerate(text):
        x.append(text[-(index+1)])
    return x

See all better. Or you can simply do,

def reverse(text):
    return ''join.(text[-(index + 1)] for index, letter in enumerate(text)])

#3

Okay got it thank you!