CODING
ADVENTURE
0 / 12 completed

CASE 04 / CHAPTER 2

Keep the minus sign

Numbers, division and signed values

IN THE STORY

Dustin recognises that Tony has stored coordinates as whole numbers. The note supplies the scale: one billion units per degree.

The idea

Numbers without quotation marks can be used in arithmetic. / means division. The underscores in 1_000_000_000 make the number easier to read; Python treats it as 1000000000. A negative longitude points west of the zero meridian. A positive one points east. Here we only calculate fictional story data; no map or location service is used.

Your mission

Divide the longitude by the same scale used for the latitude. Preserve the negative sign in its stored value.

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

Before you run it

What happens to the longitude if you remove its minus sign?

A little help?

Hint 1: a nudge

Use the variable longitude, not a newly typed positive number.

Hint 2: a closer look

The expression is longitude / scale.

How the answer works

The two results are 40.701567 and -73.775392. The minus sign survives the calculation because it is part of the value.

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

Make it yours

Change the scale to 1000. Explain why the resulting values cannot be latitude and longitude.

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

40.701567
-73.775392

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.