← Course home Next: Python loops → Code clears when you leave
MISSION 07 · PYTHON CONDITIONS

Can Rover See Ahead?

Teach Rover to check the tile in front, choose one branch, and reach the goal whether the route is open or blocked.

What’s saved: your code, predictions and answers clear when you leave this page or reload. If you turn saving on, only which puzzles you finished and how much help you used is kept on this device. Test accounts also share it, and lesson timing, with the site’s maintainer.

◇ Your mastery goalSensor choices

Complete all 4 required tasks with a correct prediction, an inspected trace and an explanation that shows the concept. At least 2 must be independent checks, without answer-level help.

✓ Qualifying tasks: 0 / 4◎ Independent checks: 0 / 2 required
PRACTICE · 1 OF 4

Welcome gate

0 / 4 checks

Rover reaches a gate that may be open or blocked. Use the same sensor program in both versions of the map, then send Rover to the marked tile. This version has a clear tile ahead. The same program must also handle the blocked version.

One program, two maps

This is the open map. The same program must reach the goal on its paired blocked map too.

Paired world to design for · start map

Start: column 2, row 3, facing E. Rover now: column 2, row 3, facing E. Goal: column 2, row 4. Walls: column 3, row 3.

1
Predict before RunPredict Rover's final square and heading on this map.
2
Write the sensor programIndent actions inside both branches.

Use if front_is_clear(): and else:. Indent each branch’s actions.

Allowed Python syntax

Allowed: if front_is_clear():, else:, move(), turn_left(), turn_right(), comments and blank lines.

Actions take empty parentheses. Both branches need an action. Nested checks are bounded to three levels. Variables, loops, elif and other conditions are outside this workshop.

FLOWCHART · INSPECTED PATH

Run a short allowed program to check its syntax and reveal its flowchart. Predict first; then inspect each event.

PLAN VIEW

Flowchart

Bounded plan · up to 64 blocks
✓ Inspected path ◆ Current step
How to read this chart

Follow the arrows from Start. Rectangles show actions. A diamond asks a question: follow the labelled TRUE or FALSE path. Only the matching path runs; both paths merge before the next step. Stacked branches are alternatives, not consecutive steps.

A Repeat uses a counter: set i = 0, check i < count, run the whole body, add one, and return to the check. Repeat 5 means five body visits; repeat 0 skips the body. The Python spelling for i in range(5): visits counter values 0, 1, 2, 3, 4: five visits. The trace numbers those visits 1–5. The Python loops workshop supports this bounded for/range form; other workshops keep their own allowed syntax.

Counter setup, increment and exit arrows explain the loop; they are conceptual, not extra recorded trace events. Highlighting follows actual actions, decisions and beginning-of-iteration markers. End is highlighted only after an inspected run finishes normally. For Python, the diagram’s counter setup and increment explain repetition; they are not executed assignments. A zero-count range visits no values and does not assign a new value to Python i.

Design on screen or sketch on paper

Edit the short program in the Python editor. Run checks its syntax before drawing the chart; your prediction stays frozen for that run. Worked examples show separate authored programs.

  1. Draw a rounded Start. Connect each step with an arrow.
  2. Put each action in a rectangle, in the order it happens.
  3. For IF, draw a diamond with a yes/no question. Label both TRUE and FALSE arrows, write each branch, then merge them.
  4. For a loop, mark the repeat count and draw its whole body. Show a counter starting at 0, a counter-less-than-count question, and a YES arrow into the body.
  5. After the body, add 1 to the counter and draw an arrow back to its question. The NO arrow leaves the loop. A count of 0 goes straight to NO.
  6. Finish with a rounded End. Trace with a finger or pencil; note position, heading and any changing values after each action.

Keep your paper sketch beside you; no photo or upload is needed. Robot doodles are optional. Magnificent robot hats are also optional.

Start or End Action Decision Order

Run an allowed program to see its actions and decisions here.

  1. Start
  2. End

MAP · OPEN AHEAD

Predict Rover’s route

2, 3 · E

Start: column 2, row 3, facing E. Rover now: column 2, row 3, facing E. Goal: column 3, row 3. Walls: none.

↑ Rover★ Goal■ Wall
Help for this sensor puzzleHints build in steps. Worked help needs a deliberate choice.

Highest help used on this case in this session: none. Worked examples and solutions count as help for both maps in this pair.

For Further Reading and Exploration

These are outside sites with their own rules. You will see a notice before you leave. Pick one, not all.

  • Automate the Boring Stuff with Python

    Free book to read online. A chapter on flow control covers if, elif and else with short examples.

    • Hands-on
    • May need an install
    • Ask an adult
  • CS50's Introduction to Programming with Python

    Free Harvard course with videos and notes. A lecture on conditionals covers if, elif and else, with examples to try.

    • Hands-on
    • Advanced
    • May count visits
  • Open Roberta Lab

    Block-based, not Python. Program a virtual robot and watch how it acts in a simulator. Logging in is only for saving.

    • Hands-on
    • Has accounts
  • Raspberry Pi Foundation Projects

    Step-by-step Python projects. Pick one that makes a choice, then change the rule. Some need hardware, so check the parts list.

    • Hands-on
    • May count visits