A. Sequential Execution: Top to Bottom
๐ฏ 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?
- Prep the ingredients (first!)
- Heat the pan
- Add the ingredients
- 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
# Add blocks and the Python code will show up here...
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
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
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
Cause: You left outimport turtle, or the order is wrong.
โ Correct Code
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)