7.reverce - 15 level Python


#1

The Link of the problem:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/1?curriculum_id=4f89dab3d788890003000096#

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):
    str(text)
    a = len(text)-1
    palabra = ""
    while a >= 0:
        palabra.append(text[a])
        a -= 1
    return palabra
    print palabra
reverse("Python!")

#2

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.


#3

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


#4

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