I have allready a few times got this error: "unsupported operand type(s) for -: 'int' and 'str'",
can anyone please explain what this means?
What exercise are you on?
currently i'm on "Practice makes you perfect", exercise 7, but i've got this error already a couple more times in earlier exercices.
The error you are receiving is because You are attempting to add together two different data types the python console gets confused when we try to do this. So to get around this you can concatenate your data types, to do this you will need to convert them both to strings or integers.
so this is my code now:
def reverse(text): r = "" for i in text: text = str(text) r = str(r) r += text[len(text) - i - 1] return r
I still get the error message after converting my 2 variables to strings. Can you see the problem? the goal is to return text in reverse ("abcd" should become "dcba").
But now if you convert them to string types but on this line you are trying to use an integer it still will not work,
Oke, but can you maybe say how I should do it then? I really don't know how else I can get the next last letter from the word...
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.