Programs that only run straight through are boring. In this unit, your code learns to think — choosing different paths based on conditions, just like you do every day.
Use ==, !=, <, >, <=, >= to compare anything.
Make your code take different paths depending on conditions.
Handle multiple possibilities with elif chains.
Use and, or, not to build complex conditions.
Put conditionals inside conditionals for sophisticated logic.
Create games and tools that respond to user choices.
Click each result to reveal the answer. Can you predict them all correctly? This previews the thinking you'll master in Lessons 2.1 and 2.4.
Click any lesson to see its challenges. Each one builds on the last.
Master comparison operators and understand how every expression evaluates to True or False.
Write your first branching code — programs that choose between two paths based on a condition.
Handle three, four, or more possibilities with elif. Build multi-way decision programs.
Combine conditions with and, or, and not to build sophisticated decision logic.
Build decisions within decisions. Learn when to nest, when to chain, and how to decompose complex logic.
Build a one-room text adventure game! Describe a scene, offer choices, branch to outcomes, and include at least one nested decision. Everything from Unit 2 in one interactive story.
Lesson 2.1 takes about 15 minutes. You'll start comparing values and predicting boolean results right away.
Begin Lesson 2.1 →