Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1
Loops Are Fun (You Can Say That Again) 67

to rotate through the names the user entered in the family list. The
program will start with the first name entered, family[0], and con-
tinue with family[1], family[2], and so on until it reaches the final
name in the list. The font = portion of this statement tells the com-
puter we want to use the Arial font, in bold style, for our names.
It also sets the font size to grow as x grows; our font size of (x+4)/4
means that when the loop finishes with x = 100, the font size will
be (100 + 4) / 4 = 26-point font—a nice size. You can make the fonts
bigger or smaller by changing this equation.
Finally, at ~, we turn the turtle left by 360/len(family) degrees
plus 2. For a family with four members, we would turn 90 degrees
plus 2 for a nice square spiral; a family of six would get 60-degree
turns plus 2 for a six-sided spiral, and so on. The extra 2 degrees
make the spiral spin to the left a bit for the swirl effect we’ve
seen in our other spirals. In Figure 4-6, we ran this program
and entered our family’s names, including our two cats, Leo and
Rocky, to get a wonderful family spiral picture.


Figure 4-6: The Payne family spiral, including our two cats, Leo and Rocky

Free download pdf