Skip to content

A. Sequential Execution: Top to Bottom

โฑ๏ธ 5 min B. import Libraries โ†’

๐ŸŽฏ Learning Goals

By the end of this lesson, you'll be able to:

  • โ—‹ Understand that code runs one line at a time, from top to bottom
  • โ—‹ Run your first turtle program

Core Concepts

What Is Sequential Execution?

Python code runs one line at a time, from top to bottom. Just like a cooking recipe, it goes in order: step 1 โ†’ step 2 โ†’ step 3.

๐Ÿ“ Analogy: A Cooking Recipe

When you cook, the order matters, right?

  1. Prep the ingredients (first!)
  2. Heat the pan
  3. Add the ingredients
  4. Done! (last!)

Code works the same way: it runs in order, from top to bottom!


Sequential Execution Flowchart

flowchart TD
    A["Line 1: import turtle"] --> B["Line 2: t = turtle.Turtle()"]
    B --> C["Line 3: t.shape('turtle')"]
    C --> D["Line 4: t.forward(100)"]
    D --> E["Program ends"]

    style A fill:#e3f2fd,stroke:#1976d2
    style B fill:#e3f2fd,stroke:#1976d2
    style C fill:#e3f2fd,stroke:#1976d2
    style D fill:#e3f2fd,stroke:#1976d2
    style E fill:#e8f5e9,stroke:#388e3c

Code Execution Order Summary

Order Command Role Description
1๏ธโƒฃ import turtle Import the turtle Write this first
2๏ธโƒฃ turtle.Turtle() Create the turtle Create a turtle object
3๏ธโƒฃ t.forward(100) Move the turtle Run whatever command you want

Try Visual Coding

๐ŸŽฏ Mission
โ—‹ Add the "Start Turtle" block and run it!
# Add blocks and the Python code will show up here...
Add blocks and the flowchart will show up here...
100


Example Code

import turtle          # 1. Import the turtle tools
t = turtle.Turtle()    # 2. Create the turtle
t.shape("turtle")      # 3. Set the shape to a turtle
t.forward(100)         # 4. Move forward by 100

What Happens

A cute turtle appears in the center of the screen and moves to the right! ๐Ÿข


๐ŸŽฏ Quiz

Quiz 1: Sequential Execution

Quiz: Sequential Execution
In what order does Python code run?
Show Answer

Answer: B) Top to bottom

Python runs code one line at a time, in order, from top to bottom. Just like a cooking recipe, it goes step 1 โ†’ step 2 โ†’ step 3!

Quiz 2: Code Order

Quiz: Code Order
In a turtle program, which line of code should run first?
Show Answer

Answer: A) import turtle

import turtle is the command that imports the turtle tools. You have to import the tools first before you can use them!


๐Ÿ”ง Debug Clinic

Problem: Nothing Shows Up!

โŒ Wrong Code

t = turtle.Turtle()  # Using turtle before importing it!
import turtle
Cause: You left out import turtle, or the order is wrong.

โœ… Correct Code

import turtle         # 1. Import it first
t = turtle.Turtle()   # 2. Then use it!
Fix: Check the order of your code - import always comes first!


Try Coding It Yourself

Take what you learned with the blocks and write it yourself in Python code!

Move the Turtle Forward

Complete the code so the turtle moves forward by 100.

Example Answer
import turtle
t = turtle.Turtle()
t.shape('turtle')

t.forward(100)  # The turtle moves forward by 100!

Result: The turtle moves to the right and draws a line!


๐Ÿงฉ Key Takeaways

What you learned in this lesson:

Concept Description
Sequential execution Code runs one line at a time, from top to bottom
Order matters import has to come first before you can use the turtle!

Review Checklist

  • [ ] Do you understand that code runs from top to bottom?
  • [ ] Do you know the basic structure of a turtle program? (import โ†’ use)