Learning map · Track 3 · beginner
Conditional Logic
Programs become useful when they react to their data: a checkout that waives delivery above a threshold, a payroll script that pays overtime, a form that rejects an impossible age. This track teaches you to write those decisions in Python. You start with a single if and its indented block, grow it into two-way and multi-way decisions with else and elif, and combine conditions with and, or and not. Along the way you learn how Python compares numbers, text and None, which values count as true or false on their own, and why floating-point totals need care.
The second half is about writing conditions people can read and trust: flattening deep nesting with guard clauses, testing membership with in, choosing between a one-line conditional expression and a full if, and matching values with the match statement. Every exercise is graded on exactly the inputs where conditional code breaks — the value on the threshold and just either side of it. The track ends with a project in which you build a shipping and discount rules engine step by step. It assumes you can use variables, f-strings, input() and type conversion; loops and functions come in later tracks.
By the end of this track you can
- Write if, if-else and if-elif-else statements that choose the right branch for every input, including values exactly on a threshold
- Combine conditions with and, or and not, and predict how short-circuiting and precedence affect the result
- Compare numbers, strings, floats and None correctly, and decide when to rely on truthiness and when to be explicit
- Restructure nested decisions into flat, readable code using guard clauses, membership tests and conditional expressions
- Use the match statement to dispatch on literal values and alternatives
- Turn written business rules (tiers, discounts, validation) into a correct, well-tested program
Lessons
- 1Making decisions with ifRun code only when a condition is true, using if, a colon and an indented block.25 min · 4 exFree
- 2Two-way decisions with elseChoose between exactly two paths with if and else, so that one of them always runs.25 min · 4 exMembers
- 3Multi-way decisions with elifPick one of many outcomes with if, elif and else, and order the conditions so tiers and brackets come out right.35 min · 4 exMembers
- 4Combining conditions with and, or, notJoin conditions with and, or and not, use short-circuiting to avoid errors, and control precedence with parentheses.35 min · 4 exMembers
- 5Comparisons in depthChain comparisons, compare text reliably, check for None with is, and compare floating-point numbers safely.35 min · 4 exMembers
- 6Truthy and falsy valuesUse any value as a condition, know which values count as false, and decide when an explicit comparison is safer.30 min · 3 exMembers
- 7Nested conditions and guard clausesPut decisions inside decisions when a second question only makes sense after the first, and flatten deep nesting with guard-style elif chains.35 min · 4 exMembers
- 8Membership tests and range checksTest whether a value is one of several options or contains some text with in and not in, and check ranges with comparisons and range().35 min · 4 exMembers
- 9Conditional expressionsPick between two values in one line with x if condition else y, and know when a full if statement reads better.30 min · 4 exMembers
- 10The match statementChoose between many exact values with match and case, combine options with |, catch everything else with _, and capture unmatched values.30 min · 4 exMembers
- 11Project: a shipping and discount rules engineBuild a complete order-quote program for an online shop in five milestones: validation, weight bands, zones, discounts and the final quote.75 min · 5 exMembers