While our turtle move program looks good, we can make a few improvements.
There are two things we can fix:• Firstly, there's quite a bit of repeated code
• Secondly, the thin black line looks a little drab.
So, let's edit the code as shown in the listing below:
from turtle import *
pencolor("blue")
pensize(5)
for i in range(4):
forward(200)
right(90)
exitonclick()
Save the code and run the program to discover what happens now. See the difference?
After the import statement we've added the pencolor
and pensize
commands. These settings will cause our turtle to draw a thick blue line.
More importantly, we've put the movement commands into a for
loop. This loop repeats the forward
and right
commands four times - a much neater coding solution.
A post from my Learn Python on the Raspberry Pi tutorial.