How a program chooses between one course of action and another: if to run a block only when a condition is true, elif and else for the alternatives, conditions nested inside one another, and the ternary operator for choosing a value on a single line.
No account needed to read a lesson · 30-day money-back guarantee
See the full learning path5
lessons
29
practice questions
22
prerequisite lessons
1 of the 5 lessons here is free to preview - the whole explanation and worked example, with no account and no email.
The editor you get
A still of the editor, not a live one
Python Editor
Editor Output
Output:
cool
You write and run Python in the browser - nothing to install, no setup. Questions are marked on the values your code produces. The snippet here is an example of the kind of code you write.
The 5 lessons in this unit. Expand any one to see what it covers. Each unlocks when its own prerequisites are passed.
01
Conditional logic
12 questions
Learn how to control program flow in Python using if and else statements, applying correct indentation to execute different code blocks based on whether conditions are true or false.
Covers
The if statement
Indentation in conditional logic
The else clause
02
elif
4 questions
Learn how to use the elif statement in Python to handle multiple branching conditions in decision-making, ensuring only the first true condition executes its associated code block.
Covers
elif
03
Nested conditionals
4 questions
Understand how to construct and interpret nested conditionals in code to handle complex decision-making scenarios that depend on multiple related conditions.
Covers
Nested conditionals
04
Conditional ternary operator
4 questions
Learn how to use Python's conditional ternary operator to assign values based on a condition in a concise, readable way.
Covers
Conditional ternary operator
05
Activity: adventure game decision engine
5 questions
Learn how to build a decision engine for a text-based adventure game by writing logic that checks player health, inventory, and weather conditions to determine the next appropriate action.
Covers
Check player health
Determine player action
Check weather
Count items
Make decision
This unit is part of our Python Done Right learning path, which contains 100 lessons. Every one of them is drawn below.
The diagnostic test lets you skip any lesson you already know, including the ones in this unit.
Hover any dot to name its lesson.
5 lessons in this unit
22 prerequisite lessons across the unit, counting every step back to the start
73 other lessons in the learning path - after this unit, or alongside it
Builds on: Basic data types, Comparisons, Python basics
Leads to: Assorted extras, Comparisons, Python basics, User-defined functions
One subscription covers every learning path, and you can test out of anything you already know.
One subscription covers every learning path · 30-day money-back guarantee
More in Conditional logic & comparisons: Comparisons