Home python Error: "SYNTAXERROR: CAN'T ASSIGN TO OPERATOR"

Error: “SYNTAXERROR: CAN’T ASSIGN TO OPERATOR”

Author

Date

Category

I am a novice in Python and for practice decided to quickly pop up the code for Expression Calculator , without resorting to the EVAL () security hole. That’s what happened to write in a couple of minutes:

act * x = 0
ACT / X = 0
ACT + X = 0
ACT-X = 0
Calc = Input ("")
If "/" In Calc:
  ACT / X = INT (Calc.split ("/") [- 2] / int (calc.split ("/") [1])
If "*" In Calc:
  ACT * X = INT (Calc.split ("*") [- 2] * int (calc.split ("*") [1])
IF "+" in Calc:
  ACT + X = INT (Calc.split ("+") [- 2] + int (calc.split ("+") [1])
If "-" In Calc:
  ACT-X = INT (Calc.split ("-") [- 2] - Int (Calc.split ("-") [1])
Print (ACT / X + ACT * X + ACT-X + ACT + X)

And everything would be nothing, but when trying to execute code, I got the following error :

file "lol.py", line 1
  ACT * X = 0
  ^
SYNTAXERROR: CAN'T ASSIGN TO OPERATOR

Tell me, please, the possible cause of the error and how to fix it.


Answer 1, Authority 100%

In the first four lines, you create 4 variables. However, the names that you give them are erroneous, it is impossible to call variables in Python. They can only contain letters, numbers (and cannot be started with the numbers) and underscores.

Arithmetic operations * - + / Use it is impossible.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions