Ms. Whitby's Classroom logo Ms. Whitby's Classroom

Lesson 02 — Sequence and Tracing

Computers follow an order

Python usually executes instructions top to bottom, one line at a time.

print("First")
print("Second")
print("Third")

Output

First
Second
Third

Reversing two lines changes the result.

A trace is a record of what a program does, step by step. Before running a program, try predicting its output.

Line executed Output added
print("Checking battery") Checking battery
print("Starting motor") Starting motor

print() normally ends with a new line, so each call displays its message on a separate line.

Practice: Startup Sequence

A robot should display these three messages in the following order:

Booting...
Checking sensors...
Ready.

The starter code contains the right messages but in the wrong order. Move the instructions into the correct sequence. View starter.

Stop and think