Skip to content

D. forward(): Moving Forward

To the final mission: โ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ 40%


๐ŸŽฏ 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.

forward(100)  # Move forward 100 pixels!

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

๐ŸŽฏ Mission
โ—‹ Add a "forward 100 pixels" block and run it. Does a line get drawn?
# Add blocks and the Python code will show up here...
Add blocks and the flowchart will show up here...
100 100 100


Example Code

import turtle
t = turtle.Turtle()
t.shape("turtle")
t.forward(100)      # Forward 100 pixels!

What Happens

The turtle moves to the right and draws a line!


Quiz

Quiz: moving forward
What's the name of the function that moves the turtle forward?
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

t.forward(0)     # 0 steps = stays in place
Cause: forward(0) Or you didn't enter a number

โœ… Correct Code

t.forward(100)   # Move 100 steps
Fix: Enter a number greater than 0!


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
import turtle
t = turtle.Turtle()
t.shape('turtle')

t.forward(100)

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