Hardware Reference
In-Depth Information
You can change the arrow to a turtle shape, as shown in Figure 4-10, by typing
the following code at the prompt:
alex.shape(“turtle”)
3. Just like in Scratch, you can create a pentagon shape by moving so many steps and
turning so many degrees. Type in the following code, pressing Enter after each line:
alex.forward(100)
alex.left(72)
Your Python Turtle drawing will appear in a different window when you run the
commands. Sometimes windows overlap and you can't see what is happening
on both of them, or you may get a white screen instead of your drawing. To get
over this problem, move the windows so that they are side by side when typing
your commands into the shell.
hese lines tell the turtle to move forward 100 steps and then turn 72 degrees to the
left. How many times would you need to type these two lines of instructions or code
into the Python shell to draw a pentagon? Continue repeating these lines until you
have created the pentagon. Figure 4-10 shows the inal code and the completed shape.
FIGURE 4-10 Drawing a pentagon in Python Turtle Graphics
Search WWH ::




Custom Search