Python Runs Top to Bottom, One Line at a Time

The dragon does your code top to bottom — one line, one step, nothing skipped.

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

The dragon explains

One line at a time

  1. The dragon: Meet your dragon! It's clever, but it can't guess. It only does what your code tells it — one line at a time.

  2. The dragon: move_right() means one step to the right. One line, one step — never more.

    example.pyPython 3
    move_right()
  3. The dragon: Three lines make three steps, done from the top line down. Watch each line light up as I do it.

    example.pyPython 3
    move_right()move_right()move_right()
  4. The dragon: Order matters. Here the up comes FIRST, so every step after it happens one row too high — I end up beside the gold, not on it.

    example.pyPython 3
    move_up()move_right()move_right()move_right()
  5. The dragon: So the order you write your lines is the order things happen. Always.

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 2

    Which order do I do these in?

    question.pyPython 3
    move_right()move_up()move_right()
    • Right, then up, then right — top to bottomCorrect
    • Whichever order gets me to the gold fastest
    • All three at the same time

    Why: Right, then up, then right — always top to bottom, one step finished before the next one starts.

  2. Question 2 of 2

    Where do I end up?

    question.pyPython 3
    move_right()move_right()move_up()
    • Two tiles right, then one upCorrect
    • On the gold
    • Straight up from where I started

    Why: Line 1 and line 2 take me two tiles right, then line 3 takes me one tile up — in that order.

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

    The dragon can smell gold three tiles away, but it only moves when your code tells it to. Each line of code is one step. There's already one move_right() — add the rest, press Run, and watch each line light up as the dragon does 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.