Python Forum
SyntaxError: can't assign to operator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: can't assign to operator
#1
Hello

I'm trying to write a little program for class, but I get an error saying "SyntaxError: can't assign to operator" and I don't know why that is.

The code I'm using:
n = int (input ('Getal waarvan je het kwadraat wil berekenen: '))
x = 1 
kwadraatx = 1 
kwadraatxmin1 = 0 
while (x < n):
  kwadraatx - kwadraatxmin1 + 2 = verschil2
  kwadraatxplus1 = verschil2 + kwadraatx
  kwadraatxmin1 = kwadraatx
  kwadraatx = kwadraatxplus1 
  x = x + 1
else:
  kwadraatx - kwadraatxmin1 + 2 = kwadraatxplus1
  print ('oplossing: Het kwadraat van ' + str(n) + 'is ' + str(kwadraatxplus1))

The message I get when I run the code:

Error:
input File "/home/main.py", line 6 kwadraatx - kwadraatxmin1 + 2 = verschil2 ^ SyntaxError: can't assign to operator



If anyone could tell my why I get this error, I would highly appreciate it Big Grin.

Thanks in advance,
Jomy
Reply
#2
what you are assigning to should be first
instead of
kwadraatx - kwadraatxmin1 + 2 = verschil2
it should be
verschil2 = kwadraatx - kwadraatxmin1 + 2
Reply
#3
Same adjustment at line 12
Output:
old: kwadraatx - kwadraatxmin1 + 2 = kwadraatxplus1 new: kwadraatxplus1 = kwadraatx - kwadraatxmin1 + 2
Cheers
Reply
#4
Ah, thank you both for the help!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020