Python Forum

Full Version: SyntaxError: can't assign to operator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
what you are assigning to should be first
instead of
kwadraatx - kwadraatxmin1 + 2 = verschil2
it should be
verschil2 = kwadraatx - kwadraatxmin1 + 2
Same adjustment at line 12
Output:
old: kwadraatx - kwadraatxmin1 + 2 = kwadraatxplus1 new: kwadraatxplus1 = kwadraatx - kwadraatxmin1 + 2
Cheers
Ah, thank you both for the help!