Calculations Priorities

Calculation Priorities (Math & Logic) — Do It In the Right Order


A huge part of programming (and math!) is doing operations in the correct order.

This lesson shows how to evaluate expressions correctly using operation priorities (parentheses, powers, multiply/divide, add/subtract) and logic priorities (NOT, AND, OR) — with step-by-step examples from the slides. 


1️⃣ Why People Get It Wrong

Many learners try to compute left-to-right only and ignore precedence.


That’s why a well-known expression tricks 73% of people

— yet the correct answer is 20 when you respect the rules. (not 36, 52, etc.).


Reason: priority for × and ÷ before + and −, and for the same rank, go left to right


2️⃣ Math Order of Operations (PEMDAS/BODMAS idea)


1️⃣ Parentheses/Brackets first
2️⃣ Exponents/Orders (e.g., 2²)
3️⃣ M/D Multiply & Divide (left→right)
4️⃣ A/S Add & Subtract (left→right)

Keep in mind parentheses first and left-to-right for same-priority ops. 


Examples:


Example 1:


Example 2:

Inside parentheses + precedence:
18 ÷ (9 − 2 × 3)

  • Compute inside: 2 × 3 = 6(9 − 6) = 3
  • Then: 18 ÷ 3 = 6 ✅ (answer = 6). 



Example 3:

Brackets within brackets:
10 − [72 ÷ (4 + 5)]

  • (4+5)=9, so 72 ÷ 9 = 8, then 10 − 8 = 2 ✅ (answer = 2).


Example 4:


Powers & grouping:
(6 × 2 − 6 − 1) × 2²

  • Inside: 6×2=12, 12−6=6, 6−1=5 → so (…) = 5
  • Power: 2² = 45 × 4 = 20 ✅ (answer = 20).


Example 5:

Nested parentheses:
4 × ( 2 + ( 7 × ( 5 − 3 ) ) )

  • Innermost: 5−3=27×2=142+14=164×16=64 ✅ (answer = 64). 


Example 6:



4️⃣ Logic Priorities (Boolean)


Parentheses → NOT → AND → OR

Same way parenthesis takes priority left to right ..etc.


Example:
True AND ((9 > 2) OR (4 + 2 = 5))

  • (9>2) is True; (4+2=5) is False(True OR False) = True
  • True AND True = True ✅ (result = True). 


16 Programming Foundations - Calculations Priorities.pdf
Complete and Continue  
Discussion

0 comments