-1

The following Python script raises syntax error:

def main(number, number2, equation):
    if equation == 1:
        number + number2 = answer

SyntaxError: cannot assign to operator is the raised error. Please help.

4
  • Sorry that i didnt put the "code look" to the code im a dumass Commented Dec 29, 2020 at 11:54
  • What do you expect the code to do? Commented Dec 29, 2020 at 11:55
  • The statement is not valid for python. Variables must be left side and expression must be the right side. For more information, en.wikipedia.org/wiki/Assignment_(computer_science) Commented Dec 29, 2020 at 12:09
  • Hey @noobie, Welcome to SO. Congrats on your efforts in learning Python. Keep it up. Statement - number + number2 = answer is not valid. It's because the assignment operator(=) assigns the right-hand side value to the left-hand side. Btw, don't get discouraged by the down votes. Keep up the learning. Commented Dec 29, 2020 at 12:21

2 Answers 2

3

You must assign (=) operation (number + number2) to variable answer in this direction.

answer = number + number2

Variable name is on right side and value, expression, object, etc. is on the left.

Sign up to request clarification or add additional context in comments.

Comments

1

In python you set variables to be equal to the their result instead of the result to be equal to the variable. So where you have put

number + number2 = answer

You need to do

answer = number + number2

As what you are doing is making the sum of number and number2 equal to answer which is not possible

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.