← Teacher guide Markdown for Prepare

Choices and lists: cheat sheet

Python Foundations with Turtle · In any playground, open Reference to copy these.

goto

Jump to a position. (0, 0) is the centre; x goes right, y goes up.

goto(0, 0)
Example
goto(80, 60)
What it draws
From the centre to (80, 60)

pencolor

Set the line colour, using a colour name.

pencolor("red")
Example
pencolor("red")
forward(100)
What it draws

begin_fill / end_fill

Everything drawn between these two lines is filled in.

begin_fill()

end_fill()
Example
fillcolor("orange")
begin_fill()
for i in range(4):
    forward(60)
    right(90)
end_fill()
What it draws

list

Keep many values in order under one name. The first item is place 0.

colours = ["red", "blue", "green"]

for each item

Work through a list, one item at a time.

for c in colours:
    pass
Example
pensize(6)
for c in ["red", "blue", "green"]:
    pencolor(c)
    forward(40)
What it draws
One line per colour in the list

pensize

Set how thick the line is.

pensize(5)
Example
pensize(1)
forward(50)
pensize(8)
forward(50)
What it draws
pensize(1), then pensize(8)

fillcolor

Choose the colour to fill shapes with.

fillcolor("blue")
Example
fillcolor("blue")
begin_fill()
circle(40)
end_fill()
What it draws

if / else

Do one thing or the other, depending on a condition.

if x > 0:
    pass
else:
    pass
Example
for x in [-90, -30, 30, 90]:
    penup()
    goto(x, 0)
    if x > 0:
        dot(30, "red")
    else:
        dot(30, "blue")
hideturtle()
What it draws
Red when x > 0, else blue

in

True if the item is in the list (or the key is in the dictionary, or the letters are in the text).

if item in bag:
    pass