CODING
ADVENTURE
0 / 12 completed

CASE 02 / CHAPTER 2 warm-up

Read the backwards note

Loops and building a string

IN THE STORY

Dustin remembers one of Tony's practice notes. It is written backwards, not encrypted.

The idea

A for loop repeats its indented instructions for each item. A string can be visited one character at a time. result starts empty. Putting the next letter before the old result reverses the order. For "cat", the successive results are "c", "ac" and "tac". Four spaces mark the instructions inside the loop.

Your mission

Complete the loop so the note reads forwards. Trace the first three letters on paper before running it.

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

Before you run it

Would result + letter reverse the note, or keep its original order?

A little help?

Hint 1: a nudge

The new letter must go before what you already have.

Hint 2: a closer look

Assign letter + result back to result.

How the answer works

Each letter is placed at the front of the growing result. Reversing text is a puzzle transformation, not a way to protect a secret.

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

Make it yours

Try an empty string, one letter and a word that reads the same in both directions.

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

trust me

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.