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

(vip2019) #1

46 Chapter 3


Figure 3-8: A colorful text spiral

l sts: Keeping i it all together


In addition to strings and number values, variables can also con-
tain lists. A list is a group of values, separated by commas, between
square brackets, []. We can store any value type in lists, including
numbers and strings; we can even have lists of lists.
In our spiral programs, we stored a list of strings—["red",
"yellow", "blue", "green"]—in the colors variable. Then, when our
program needed to use a color, we just called the t.pencolor() func-
tion and told it to use the list colors to find the name of the color
it should use next. Let’s add some more color names to our list of
colors and learn one more input function in the Turtle package:
numinput().
To red, yellow, blue, and green, let’s add four more named colors:
orange, purple, white, and gray. Next, we want to ask the user how
many sides their shape should have. Just as the turtle.textinput()
Free download pdf