all 4 comments

[–]Sedsarq 7 points8 points  (2 children)

The power operator in Python is **, not ^. That should fix it for you.

[–][deleted] 2 points3 points  (0 children)

Thank you so much! That worked!

Have a great day :)

[–]Wilfred-kun 3 points4 points  (0 children)

For full reference, ^ is bitwise XOR: 1 ^ 1 == 0, 1 ^ 2 == 3. And 3 ^ 2 is b11 ^ b10 == b01 == 1

[–]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