CODING
ADVENTURE
0 / 12 completed

CASE 05 / CHAPTER 4

Which note matches?

Comparison, conditions and fingerprints

IN THE STORY

Christine finds two notes. Tony separately supplied a trusted fingerprint for the exact text of the correct note.

The idea

== compares two values and produces True or False. if chooses a block of instructions when a condition is true; else handles the other case. A cryptographic hash turns data into a fixed-size fingerprint. This activity uses the supplied hashlib helper. It compares fingerprints; it does not reverse one to read a message. A trusted reference matters: a fingerprint from an untrusted person does not prove authorship.

Your mission

Compare actual with expected so only the unchanged note is accepted.

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

Before you run it

Will changing the final full stop to an exclamation mark still match?

A little help?

Hint 1: a nudge

Use == for comparison. A single = is assignment.

Hint 2: a closer look

The if condition should be actual == expected.

How the answer works

The exact note matches. Altering the text changes its fingerprint in this example. The comparison says the bytes match the trusted reference; it does not say a program is safe to run.

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

Make it yours

Try changing a letter, adding a space and removing the punctuation. Keep expected unchanged.

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

The note matches.

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.