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

(vip2019) #1

64 Chapter 4


Because z is the last line indented under the while loop v, the
new name that the user enters is passed back up to v so the while
loop can check whether it’s an empty string. If it’s not empty, our
program will start the for loop to print the new name 100 times. If
the name is an empty string, that means the user pressed enter
to end the program, so the while loop at v skips down to {, and we
thank the user for playing. Figure 4-5 shows the output of the pro-
gram when my sons ran it.

Figure 4-5: My sons ran SayOurNames.py and put in the names of everyone
in our family!

The Family Spiral


Now that we can ask for a list of names and print them to the
screen, let’s combine the name printer loop with one of our pro-
grams from Chapter 3, SpiralMyName.py on page 45, to create
a colorful spiral of our family’s or friends’ names.
Our new, combined program will be different from the name
repeater in SayOurNames.py in a few ways, but the most important
Free download pdf