The code works, but it somehow doesnt satisfy the console!


#1

I hope this finds you in a good state, I have been using this code
def reverse(text):

l = len(text)-1
p = " "

for i in text:
    n = text[l]
    p += str(n)
    l -=1
return p

it inverts the text and display it inverted, but it keeps giving me this message

Oops, try again. Your function fails on reverse("Python!"). It returns " !nohtyP" when it should return "!nohtyP".

any ideas ?


#2

@rubyblaster57306,
as you initialize your p-variable as having 1 space you get " !nohtyP"


#3

We can simplify your code...

def reverse(text):
    p = ""
    for x in text:
        p = x + p
    return p