Reverse not storing in an array


#1



Reverse

Is printing a list of letters instead an array

I expect to print an array with all the letters


def reverse (text):
    lenght=len(text)
    reversedtext=''
    while lenght>0:
        lenght=lenght-1
        x=text[lenght]
        reversedtext=x+reversedtext

reverse("cocacola")


#2

It's returning None, because you didn't specified return.
You should return reversedtext after while loop.
Also, your code is going to "rewrite" your text letter by letter, in original order. If you want to reverse, you must change
reversedtext = x + reversedtext to reversedtext = reversedtext + x

You can use lenght -= 1 instead of lenght = lenght - 1 and reversedtext += x instead of reversedtext = reversedtext + x

What do you mean by array? In Python list = array.