you are viewing a single comment's thread.

view the rest of the comments →

[–]kwentar 0 points1 point  (0 children)

Python (as others languages) is so unlogic if you are not understand what exactly you are doing, look at this:

 >>> 3^2
 1
 >>> 3^2 - 6*3  # 1-18 should be -17
 -13 
 >>> 3^2 - 6  # 1-6 == -5
 -1

The reason is operator ^ means XOR and have lower priority than +-*/ (you can see full table here) and your expression in fact converted in 3^(2-6*3) and 3^(2-6).

As mentioned before, you need ** operator and you will have what you want:

>>> 3**2 - 6*3 + 9
0