How Python Code Runs: The Full Picture, for Kids

Order, no gaps, no auto-repeats, changes only forward — everything at once.

  • Lesson 4 of 4
  • Free
  • Ages 10+
  • 3 hands-on levels
Try this lesson interactivelyReal Python, running in your browser.

The dragon explains

The Dragon's Final Check

  1. The dragon: You know three things about how I follow your code now. Let's put them together.

  2. The dragon: One: top to bottom, always — one line, one step.

    example.pyPython 3
    move_right()move_right()
  3. The dragon: Two: nothing happens unless you wrote it. Walking never grabs, and one line never repeats itself.

  4. The dragon: Three: a change only counts for the lines after it. The key has to be in my claws BEFORE I reach the gate.

    example.pyPython 3
    move_up()move_up()grab()move_down()move_down()move_right()move_right()move_right()
  5. The dragon: That's everything. The challenge ahead just asks you to use all three at once.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 1

    No key, four steps right. Where do I end up?

    question.pyPython 3
    move_right()move_right()move_right()move_right()
    • Right in front of the gateCorrect
    • Next to the gold
    • Just past the gate

    Why: In front of the gate. Two steps get me there, and the last two just bonk — the key was never picked up.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    A short warm-up before the big cave. Pick up the gem on the way, then finish on the gold — one line for every step and one for the grab. Nothing happens unless you write it.

  2. +2

    PracticeTwo more, on your own

Try it yourself — in real Python.

This lesson is part of a free topic: every lesson in it is free, and no card is needed.

Start this lesson for real

Stuck three times? The game offers the answer — unasked.