Search code examples
pythonoperator-precedence

Order of precedence equation


Evening all, I am more or less familiar with the order of precedence but this one confuses me and I have an exam tomorrow so yer :d....

Ok so, 6-2/2+5

Is it:

2/2 = 1
1+5 = 6
6-2 = 4
then 4+6 = 10

The part that confused me is once you have in step 3 the value 4 then you just add what ever is left in the equation to the total ?


Solution

    1. (2/2) = 1 division is performed first
    2. (6-(1)) = 5 + and - have equal precedence, so we go left to right, hence 6 - (2/2) is done first
    3. (5)+5 = 10 finish it by doing addition