7.reverce - 15 level Python


The Link of the problem:

Hi someone can help me with this code?
I dont know what error i do in .append section and other lines.

"Oops, try again. Your code looks a bit off--it threw a "'str' object has no attribute 'append'" error. Check the Hint if you need help! "

This is my code:

def reverse(text):
    a = len(text)-1
    palabra = ""
    while a >= 0:
        a -= 1
    return palabra
    print palabra


That line does nothing, and since the input is already a string, it is also moot.

That makes this a string object. The str class has no append method since strings are immutable.

We can however re-assign a string to its old variable.

palabra += text[a]

This will join the two strings, the current and the new, and assign the finished result back on to the old variable.

This line is unreachable after return and should be removed.


Wow thanks i tryed it with more caution and effort following your tips and it works!


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