CODING
ADVENTURE
0 / 12 completed

CASE 08 / CHAPTER 8

Choose the allowed commands

Lists, membership and filtering

IN THE STORY

Dustin tests a local model of a drone controller. In this fictional simulator, the approved commands are hover, land and return.

The idea

A list groups values. in asks whether a value occurs in a collection. append adds an item at the end of a list. Filtering builds a new list containing only items that meet a rule. Here the input is ordinary text, not radio traffic. This program controls no device and blocks no real transmission.

Your mission

Complete the condition so track and erase are excluded while the approved commands remain in their original order.

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

Before you run it

What should the output be if every input command is disallowed?

A little help?

Hint 1: a nudge

Check each command against the supplied approved list.

Hint 2: a closer look

Use command in approved.

How the answer works

The result is a new list containing hover and land. Input, rule and output are visible. A real controller would require authentication and other safeguards; this is a model of one rule only.

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

Make it yours

Add return and test again. Then try LAND in capitals and explain the result.

drone_simulator.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

['hover', 'land']

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.