What is wrong with my code?


The goal of this exercise was to create function that returns the characters of a string in reverse. What is the wrong with my code? Please identify if it is a syntax error of some sort, a fundamental error in the way I am going about completing this exercise, or another error of some sort. Please be specific on what I am doing incorrectly.
def reverse(text):

    text = str(text) # I convert any input into a string
    length = len(text)
    word = ""
    while length - 1 >= 0:
        word = word + "%s" (text[length-1])# i concatenate each succesive character
        length = length - 1
    return word

Thank you for having read thus far, and thank you for your answer. If something is unclear in what I am trying to do in my code, please ask, and I will respond.


That should not be in the actual string, but in a print expression. It can be removed. Try that and see what happens.


str.__mod__ doesn't require print
(% where the left operand is a string, and this isn't present in the code anyway)

Placing two values next to each other isn't valid Python code:

5 2
And there's probably a syntax error pointing right at that
.. actually no. Because the parentheses used in that way are the call operator, and the name on the left side is a string, so the code there says to call a string, but strings are not callable.

''() # can't call strings


hahah, never mind, i went away from my code, i figured it out just now, the issue was i didn't put the percent symbol on the concatenating line, after the "%s", like this:

       word = word + "%s" % (text[length-1])# i concatenate each successive

whereas instead i did it like this, incorrectly:

       word = word + "%s" (text[length-1])# i concatenate each successive

it was a simple careles issue of syntax, of concatenating string, oy vey, i truly hate careless mistakes, because u can't learn from them, u always knew and know they are wrong, but its just a lack of attention. Mistakes that are conceptual i am more fond of, because i can learn from them.


You can learn to better identify them, see how your code relates to the error message that strings can't be called?

We make mistakes there's no getting around it. So we learn how to identify and fix them. And of course avoiding making them in the first place, but it'll still happen.