← Back to course
Python 11-12 / Week 01 / Mission Quest
6/6
Week 01 · Back at the Terminal

Mission Quest

Mission Quest: Be the computer
// Review fast, trace before you run, and name the three kinds of error
⏱ about 30 min

Saturday: Mission Quest: Be the Computer

The maker space is quiet on Saturday. Comet has written a six-line program on a large sheet of paper.

"No screens today," she says. "One person reads the program aloud. The other one is the computer and fills in the trace table."

Wren rules neat columns on a fresh page of graph paper. "What does the evidence say?" he asks. "If two people trace the same program, they should get the same table."

Nova dims her lights to a soft glow. "How can I help?" she asks. "Read slowly. The computer only does exactly what each line says."

Comet passes you the sheet. "Find a family member, lead programmer. You are the computer first."

The two programs

Here are the two programs for the game. Each one runs in Python just as shown, so you can check your table at the computer afterwards.

# be_the_computer.py
battery = 100
steps = 0
while battery > 80:
    battery = battery - 5
    steps = steps + 1
print(steps, battery)
# be_the_computer_2.py
total = 0
for n in range(1, 5):
    total = total + n
    print(n, total)
print("done")
◇ BE THE COMPUTER
You need paper, a pencil and the two programs above. One person is the reader and one is the computer.
The reader reads be_the_computer.py aloud, one line at a time. The computer writes each new value of battery and steps in a trace table.
When the while line comes round, the reader asks: is battery more than 80? The computer answers from the table.
At the print line, the computer says what would appear on the screen.
Swap roles for be_the_computer_2.py. Then compare your tables. Did you both get the same rows?
Line read aloudbatterysteps
battery = 100
steps = 0
(keep adding rows)
For a grown-up
Being the computer means doing only what each line says, never what you expect it to say. Read slowly and let the learner check each value.
Talk about it: when you swapped roles, was it easier to read or to be the computer? Why might programmers trace on paper?
CHECK YOUR TABLES
  • Read the question.
  • Tap your answer.
What does be_the_computer.py show?
How many times does steps = steps + 1 run?
What is the last number line be_the_computer_2.py shows, just before done?
StatementTrue or false?
Two careful tracers of the same program get the same trace table.?
print("done") in be_the_computer_2.py runs 4 times.?
WHY THIS EXERCISEA program does exactly what its lines say, and print("done") sits after the loop, so it runs once.

You were the computer today. Next week the crew turns Comet's dicts into real objects with a class.

← Friday