Module 3 · Making decisions in Python · Lesson 5 of 7
Analyzing code samples
The best way to get comfortable with conditions is to trace them — to read a program and predict what it does before running it. Let's do a couple. Here's a grader. With score = 75, which line prints?
The key to an elif chain is that Python tries each condition in order and stops at the first True one. 75 >= 90? No. 75 >= 80? No. 75 >= 70? Yes — so it prints C and skips the rest. The order of the branches really matters.
Conditions can also nest: an if inside another if, each with its own indentation. Trace this one before you run it — does the “Enjoy the show!” line happen?
Follow the indentation like a map: age >= 18 is True, so we step inside; there has_ticket is True, so we get in. Reading code by its indentation is a skill worth practising — it's how you'll spot bugs.