7。 reverse


#1



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


The error code is File "python", line 6
SyntaxError: can't assign to function call

Oops, try again. Did you create a function called reverse? Your code threw a "global name 'reverse' is not defined" error.


def reverse(text):
    reversetext = ''
    while len(text)> 0:
        n = text[len(text)-1: len(text)]
        reversetext & str(n)
        len(text) -= 1
    return reversetext


#2

def reverse(text):
    reversetext = ''
    i = len(text)
    while i> 0:
        n = text[len(text)-1: len(text)]
        reversetext & n
        i -= 1
    return reversetext

I changed the code a bit and got another error message:

Oops, try again. Does your reverse function take exactly one argument (a string)? Your code threw a "unsupported operand type(s) for &: 'str' and 'str'" error.


#3

Do you mean to write,

    reversetext += n

?


#4

Yes, like string append


#5

Wow, it worked now!!! Thanks a lot!