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

(vip2019) #1

74 Chapter 4


•    Give examples of situations in which you would use each type
of loop.
• Design and modify programs that use nested loops.

p ogramming Challengesr
Try these challenges to practice what you’ve learned in this
chapter. (If you get stuck, go to http://www.nostarch.com/
teachkids/ for sample answers.)

#1: Spiral Rosettes


Think about how you might modify the ViralSpiral.py
program to replace the small spirals with rosettes like
those in Rosette6.py (page 58) and RosetteGoneWild.py
(page 60). Hint: first replace the inner loop with an inner
loop that will draw a rosette. Then, add the code to change
the colors and sizes of the circles in each rosette. As an
added touch, change the width of the pen slightly as your
circles get bigger. When you finish, save the new program as
SpiralRosettes.py. Figure 4-8 shows a drawing produced by
one solution to this challenge.

Figure 4-8: A spiral of rosettes from one solution
to Programming Challenge #1
Free download pdf