Python conditionals for beginners
Make decisions in Python with comparisons, if statements, elif, else, and exception handling.
Understanding conditional execution
Conditional statements choose which code runs. Start with a comparison that produces True or False, then indent the statements belonging to each branch. The exercises help you distinguish separate conditions from mutually exclusive branches and handle invalid input.
temperature = 18
if temperature < 20:
print("Bring a jacket")
else:
print("Enjoy the sunshine")Only one branch runs here. Try a temperature of 24 and predict the output before running it.
What you will practice
Work through eight coding missions, then test your understanding with ten multiple-choice questions. Each mission provides starter code, a hint, and feedback after you run it.
- Boolean comparisons — Boolean expressions
- Logical combinations — Logical operators
- Choose even or odd — Alternative execution
- Three-way comparison — Chained conditionals
- Guard the division — Short-circuit evaluation of logical expressions
- A safer temperature input — Catching exceptions using try and except
- Overtime with error handling — Exercises: Exercises 1 and 2
- Score to letter grade — Exercises: Exercise 3
Your chapter progress is saved in this browser. Complete all 18 checks to unlock a certificate at your earned practice score, and download your notebook or grade report to keep a copy.
Read, practice, and try again
For the chapter reading, see Python for Everybody: Conditional execution by Charles R. Severance (CC BY 4.0). ZHUDDLE adds its own practice activities and scoring. The browser runs Python after its first interpreter download; no local installation is required.
Start the conditionals exercises →