Skip to content
CareerBridge
← Python: your first useful programs
GUIDED STARTER LESSON

Make a decision with if

Use a condition to choose a program branch.

Understand the idea

An if statement runs its indented block when its condition is true. An else block runs when that condition is false.

The == operator compares values. A single = assigns a value to a name.

A message in a program is not proof that a real device has been tested. This exercise uses a fictional status.

Worked example

With status set to offline, the program prints Ask about the connection. Changing it to online selects the other branch.

status = "offline"
if status == "offline":
    print("Ask about the connection")
else:
    print("Record the current status")