Card 5: If / Else
Module 2: Making Decisions
1 The Hook
The IF Statement is like a Club Bouncer.
It checks your ID (Condition).
- IF you are old enough -> "Come in!"
- ELSE (otherwise) -> "Go home!"
2 Worked Example
Notice the colon (:) and the indentation.
PREDICT
age is 15. What prints?
print("Vote")
else:
print("Wait")
Input Required
Interactive Editor
🥉 New High Score
1. Copy the code.
2. Change the Threshold from 50 to 90.
3. Run it to check if it says "Failed" (because 75 is not > 90).
if score > 50:
print("Winner")
🥈 Missing Colon
The code below is broken. We forgot the Colon (:)!
Fix it so it runs.
🥇 Password Protection
1. Ask the user for a pin (stored as text).
2. If pin == "1234", print "Unlock".
3. Else, print "Locked".