Error with Function Assignment

subtractFromAmount = db[subtractFromUser]["balance"]
        int(subtractFromAmount) -= int(amount)
        additionToAmount = db[additionToUser]["balance"]
        int(additionToAmount) += int(amount)

With this code I get this error:

Syntax Error: ‘Function call’ is an illegal expression for argumented assignment.

As is probably obvious, I want to get a value in a dictionary of a key and subtract it by another number. Then I want to get a value in a dictionary of a different key and add it by the number. How can I do this without getting the error?

That is wrong in so many ways. You can never assign a function call.

I highly suggest learning the way, and understanding how errors work, so you don’t have to ask here all time, and when you do ask you know what the actual problem is. (If it says “syntax” error it is always a problem with your code alone, and has nothing to do with any libraries)

The fix would be to just do subtractFromAmount = and save it to the db as an int.


I am taking a professional Python course, and the next lecture is about just that!

I’m not sure I understand - I need to know what the value is in the database, subtract a number from it, then put that value back in the database. How can I get the database value and store it in a variable as an int and not a function call?

1 Like

Change this:

int(subtractFromAmount) -= int(amount)


subtractFromAmount -= int(amount)

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