D. forward(): Moving Forward
๐ฏ Learning Goals
By the end of this lesson, you'll be able to:
- โ
forward()You can use a function - โ Understands what a pixel is
- โ Understands that the turtle draws a line as it moves
โก 30-Second Challenge
Run the code below and try changing the numbers!
Did it work? Let's learn more about it below!
Core Concepts
What is forward()?
the turtle Move forwardIt's a function that does this.
What is a pixel?
A pixel is the smallest dot on the screen. The bigger the number, the farther it moves!
๐ Check the Pixels Yourself!
In the interactive demo below, press the zoom button to see for yourself what pixels look like!
A line is drawn!
When the turtle moves, a line is drawn where it passed. ๐๏ธ
๐๏ธ A Turtle That Moves with the Pen Up
By default, the turtle is holding its pen down. As it moves, a line is drawn automatically!
Try Visual Coding
# Add blocks and the Python code will show up here...
Example Code
What Happens
The turtle moves to the right and draws a line!
Quiz
t.____(100)
Show Answer
Answer: forward
t.forward(100)moves the turtle forward by 100 pixels.
๐ง Debug Clinic
Problem: the turtle won't move!
โ Wrong Code
Cause:forward(0) Or you didn't enter a number
Try Coding It Yourself
Take what you learned with the blocks and write it yourself in Python code!
Moving forward
t.forward()Move the turtle forward with it.
Example Answer
Result: The turtle moves 100 pixels to the right, drawing a line!
Moving various distances
Try moving several times! Plug in different numbers like 50, 100, 150.
forward() syntax practice
- Move 150 pixels:
t.forward(150) - Move 200 pixels:
t.forward(200) - A pixel is the smallest Point (unit)
Review Checklist
- [ ]
forward()You can explain what a function does - [ ] You can explain what a pixel is
- [ ] You know that a line is drawn when the turtle moves
๐งฉ Key Takeaways
What you learned in this lesson:
| Concept | Description |
|---|---|
| forward(n) | Move the turtle forward n pixels |
| Pixel | The smallest dot on the screen (100 pixels โ 2.5cm) |
| Drawing a line | A line is drawn automatically when you move |