Conditionals

Every program you've written so far runs the exact same way every time. Conditionals change that — your code can finally make decisions, which means Zara's story can actually branch.

What You'll Learn

  • if — runs a block of code only when a condition is True
  • elif / else — more conditions to check, then a catch-all; Python runs the first True branch and skips the rest
  • and / or / not — combine conditions (both must be true / at least one must be true / flip a bool)
Watch out for: = assigns a value; == compares two values. Mixing them up in a condition (if health = 100:) is actually a SyntaxError in Python — it won't run at all, which is a fast, loud signal once you know what that error means.

Today's Activity

Today's practice happens inside the notebook below — work through it top to bottom:

  1. A worked example, fully written out
  2. Two guided practices — change a few values, then fill in some blanks
  3. Two independent practices — write your own from scratch, different scenario each time
  4. An optional stretch, if you want to go further
  5. One check-your-understanding question to close

Download the notebook, save it into your 1_foundations folder in your cloned repo, and open it in VS Code. Commit once you've saved it, then commit again when you're done for the day.

Download 1.4_Conditionals.ipynb

New to notebooks? See Using Jupyter Notebooks first.

What's Next

Coming up: Project 1A — Character & First Choice, your first checkpoint. You'll use exactly what 1.1–1.4 taught you to create a character and write one branching decision.