CODING
ADVENTURE
0 / 12 completed

CASE 09 / CHAPTER 10

Plan Tony's exit

State and a coordinate model

IN THE STORY

Christine plans the route through a fictional floor plan. The playable maze adds walls, Tony and an exit; this short activity teaches the movement first.

The idea

State is the information a program remembers at a moment. Here x is a column and y is a row, counted from zero. Moving east adds one to x. Moving south adds one to y. Each loop iteration updates the position. This small example supports only E and S; the complete game handles four directions and checks walls.

Your mission

Complete the south step. Later, run tonys_exit.py from Build Game One to try the full maze.

Replace ____ with the missing expression, then choose Run code. Match the expected output before trying your own changes.

Before you run it

Where will the route EESS end if it starts at column zero, row zero?

A little help?

Hint 1: a nudge

A south step changes the row, not the column.

Hint 2: a closer look

Increase y by one: y + 1.

How the answer works

The position is column 2, row 2. elif means “otherwise, if”. In the full game, reaching the exit before finding Tony does not count as success.

This replaces the code in the editor. Save your version first if you want to keep it.

Make it yours

Add N and W rules to your copy. In the full game, trace each step of EESSEEESS and explain why it succeeds.

rescue_route.pyPYTHON 3

Four spaces indent a block. Ctrl / ⌘ + Enter runs your code. Tab moves to the next control.

OUTPUTPython loads when you run
Your program's output will appear here.

Take a guess. Try a line. See what happens.

Expected output

Position: 2 2

Code runs on your device. The first run downloads the Python engine (about 10 MB); later runs use the browser cache. Stop ends a run without losing your code.