Reverse - Numbers insteads of strings


#1



Oops, try again. Your function fails on reverse("Python!"). It returns "[[6], [5], [4], [3], [2], [1], [0]]" when it should return "!nohtyP".

Hello Everyone,

Could you help me please? I am trying to understand what is my mistake in this function. Why is it returning numbers while the argument is a string?
Thanks in advance!


def reverse(text):

    n=len(text)
    test=[]
    while n>0:
        test.append(n-1)
        n-=1
    return test    
reverse('Python!')


#2

You say that there's a mistake, that suggests that your code should be for the most part correct.
But I don't see it amounting to reversing a piece of text, it's very far off.
You should probably consider what actions your code needs to carry out. Before you write any code, make sure that you're convinced that carrying those actions out has the desired effect (reversing the text)
You can write those actions as comments, and then later fill in the corresponding code. That way you can check the overall logic by reading the comments, and you can compare each piece of code with the comment that describes what it's supposed to do.

You seem to have gone for the strategy of counting down from the last index to the first. That's fine. But you haven't really done anything else after that, there's a whole lot missing. What else needs to happen?


#3

Ok
Thanks for the tip!
I'll try to be patient and find out!


#4

did anybody get it ??


#5

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