Booleans and conditionals
- Stage
- 1
- Module
- M1.4
- Lessons
- 1
In this module
- Compare values with
==,!=,<,<=,>,>=, and test membership within. - Branch a program's logic with
if,elifandelse. - Combine conditions with
and,orandnot, and chain comparisons like0 <= x <= 10. - Write a short either/or value in one line with a conditional expression.
Before this module
Lessons
Practice
Try these on the judges. Each link opens the problem on WMOJ or DMOJ.
- 2021 J1Boiling Water (opens on WMOJ in a new tab) WMOJ
Turn a boiling point into an atmospheric pressure and a three-way elevation reading.
- 2023 J1Deliv-e-droid (opens on WMOJ in a new tab) WMOJ
Score a delivery robot's run from its package count and its collisions, with a bonus condition.
- 2026 J1Concert Tickets (opens on WMOJ in a new tab) WMOJ
Decide whether a concert-goer can buy their tickets from the remaining supply.
- 2017 J1Quadrant Selection (opens on DMOJ in a new tab) DMOJ
Decide which quadrant a point falls in from the signs of its coordinates.
Why DMOJ: Tries the same kind of decision on DMOJ, which holds 2014 to 2020.