Concept
Order of Operations (PEMDAS)
Python respects standard math rules: 1. Parentheses `()` 2. Exponents `**` 3. Multiply & Divide `*`, `/`, `//`, `%` 4. Add & Subtract `+`, `-`
python
print(2 + 3 * 4) # 14 (multiplication first!)
print((2 + 3) * 4) # 20 (parentheses win!)# 19. Order of Operations (PEMDAS) Python respects standard math rules: 1. Parentheses `()` 2. Exponents `**` 3. Multiply & Divide `*`, `/`, `//`, `%` 4. Add & Subtract `+`, `-` ```python print(2 + 3 * 4) # 14 (multiplication first!) print((2 + 3) * 4) # 20 (parentheses win!) ``` When in doubt, slap parentheses around it. Nobody ever got fired for adding parentheses.
Checkpoint
What does `(2 + 2) * 5` output?
Practice
Write an expression that adds `10` and `5`, and then multiplies the whole thing by `2`. Output must be `30`!
01
Tap code blocks below to assemble
Available Blocks