Hi, could someone tell me what's wrong with my code? I know that first of all, it's too short but I don't know what's missing. I'm stuck, please help me.

The error that shows up:
Oops, try again. Your function fails on reverse("Python!"). It returns "None" when it should return "!nohtyP".

def reverse(text):
    lst = []
    text = str(text)
    for char in text:
        lst.append(text[len(text) - 1])
    print lst


This should be a return statement. That's why it is returning None.

Is not text already a string?

Does not look quite right.


def reverse(text):
    lst = []
    text = str(text)
    x = 1
    while x <= len(text):
        lst.append(text[len(text) - x])
        x += 1
    return lst

I came up with something like this, but still I don't know how to make one word from the elements of list lst.


Python has a special function for joining elements to form a string (they must be string type, though. We cannot join() numbers unless they are first converted to str()

lst = ['a','b','c','d']
string = ''.join(lst)
print string    # abcd.

The syntax for join() is,

'separator in quotes' dot keyword token open paren list close paren

To join letters to form a word, the separator is the empty string, '' or "".

To join words to form a sentence, the separator is a space character, ' ' or " ".

To join elements to form a string that is a list, the sepatator would be, ', ' or ", ".


Oh, I forgot about that, thanks for your help, everything works properly :slight_smile:


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