BEGINNER PYTHON · CHAPTER 03

Python conditionals for beginners

Make decisions in Python with comparisons, if statements, elif, else, and exception handling.

Practice Python conditionals →Download the chapter notebook

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.

  1. Boolean comparisons — Boolean expressions
  2. Logical combinations — Logical operators
  3. Choose even or odd — Alternative execution
  4. Three-way comparison — Chained conditionals
  5. Guard the division — Short-circuit evaluation of logical expressions
  6. A safer temperature input — Catching exceptions using try and except
  7. Overtime with error handling — Exercises: Exercises 1 and 2
  8. 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 →