LESSON 5

Conditions

Learning objective: Make decisions with if, elif, and else.

Understand

Conditions let a program choose what to do.

Python uses if, elif, and else, with indentation (not braces) to define blocks. Consistent indentation is required — it is part of Python's syntax.

Analogy: A condition is a fork in the road; indentation shows which path belongs to which choice.

See It in Action

Choosing a message:

score = 82
if score >= 90:
    print("A")
elif score >= 80:
    print("B")
else:
    print("C")
How it works: Python checks each condition in order and runs the first indented block that matches — here it prints 'B'.

Try It Yourself

  1. Write an if/else based on a number.
  2. Add an elif branch.
  3. Break the indentation and read the error.

Quick Quiz

How does Python define a block of code?

Challenge

Write a grader that prints a letter grade from a score.

Success condition: Your grader prints the right grade for several scores.