def calculate_error(m, b, point):
    x_point, y_point = point  
    y = m*x_point + b
    distance = abs(y-y_point)
    return distance

print(calculate_error(2, 0, (5, 5)))

I ran the code above and it worked. But I do not understand why it doesn't work when I tried setting point = x_point, y_point instead?

  • $\begingroup$ x_point, y_point is what you've used? Isn't it? $\endgroup$ – nikhilbalwani May 7 '20 at 15:47
  • $\begingroup$ yes. That's is correct. $\endgroup$ – Ben May 7 '20 at 15:49
  • 2
    $\begingroup$ Questions specific to python are off-topic here, unfortunately. You can try your luck at Stack Overflow. $\endgroup$ – Yuval Filmus May 7 '20 at 15:51

In most programming languages, the = operator is an assignment operator which assigns to the left the values on the right.

Sometimes there are variations on the semantics, but it rarely means equal.

Coincidentally, though, which may cause confusion, after x = y, that is, after x has been assigned the value of y, the two values are equal, denoted in many languages (including Python) with x == y.

Hence, if you write

y = 3
y = x

the program crashes because x hasn't been given a value.


Not the answer you're looking for? Browse other questions tagged or ask your own question.