It reverses the word but it returns it in list format, how do I change it into 1 string.

Here is the error message:

Oops, try again. Your function fails on reverse("Python!"). It returns "['!', 'n', 'o', 'h', 't', 'y', 'P']" when it should return "!nohtyP".

def reverse(text):
    x = len(text) - 1
    y = []
    while x > -1:
        x = x - 1
        return y


you could use .join(), which would be the best way to achieve this


Don't worry, just worked it out.

    y = y + text[x]

instead of



thank you
i'll try that as well


you made y a string? I would personally advice against it, strings are immutable in python while lists are mutable, so using a list + built in join function is more efficient.


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