🚦 Making decisions
Why: Branch your programs with if / elif / else.
Unlocks: Loops — and programs that react to the world.
In the Logic Lab you wired switches through AND, OR and NOT gates, and the bulb lit only when the condition was true. Python's if is that circuit, written as code — programmers call it a conditional: if this condition is true, run these lines; otherwise, skip them.
Two crucial details:
1. The condition temperature > 30 is a yes/no question — exactly a logic-lab bulb. Comparisons: > < >= <= == (equals — two signs, because one = already means “fill the box”) and != (not equal).
2. The indentation — those 4 spaces — is how Python knows which lines belong inside the if. “Have a nice day” isn't indented, so it runs no matter what.
else adds a second road: one runs when the answer is yes, the other when it's no. elif chains more questions in between:
Your turn to build. A bouncer program: if the name is Fayez, greet the boss; anyone else gets a normal hello.
Why does Python use == in conditions instead of = ?
What does the indentation (the 4 spaces) under an if tell Python?
🔍 Go deeper: step through an if/elif/else and watch which branches the machine actually visits → PyDebug: Making Decisions.