Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
Loops Are Fun (You Can Say That Again) 55 This code works, but doesn’t it feel repetitive? We typed the code to draw a circle fo ...
56 Chapter 4 numbers, you can enter different numbers inside the parentheses of the range() function: >>> list(range(3) ...
Loops Are Fun (You Can Say That Again) 57 4, and 5 a total of four times, generating a rosette of four circles on the top, left, ...
58 Chapter 4 Modifying our for Loop to Make a rosette with six Circles Now that we’ve built our own for loop together from scrat ...
Loops Are Fun (You Can Say That Again) 59 and w six times each. At v, we’re still drawing a circle with a radius of 100. At w, t ...
60 Chapter 4 360 degrees by that number, and we’ll find the number of degrees to turn left each pass through the loop. Type and ...
Loops Are Fun (You Can Say That Again) 61 Run the program and try your own numbers. You can even make a rosette of 90 circles, o ...
62 Chapter 4 run our program, but we need to give them the ability to play again without having to reload and run the program ev ...
Loops Are Fun (You Can Say That Again) 63 if one of them is greater or less than the other, or if they are equal or not equal. I ...
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 ...
Loops Are Fun (You Can Say That Again) 65 difference is that we can’t just print each name one by one; to draw our spiral, we ne ...
66 Chapter 4 Ask for the first name v name = turtle.textinput("My family", "Enter a name, or just hit [ENTER] to end:") Keep ask ...
Loops Are Fun (You Can Say That Again) 67 to rotate through the names the user entered in the family list. The program will star ...
68 Chapter 4 p tting u it All Together: spiral goes Viral We’ve seen the power of loops: they take pieces of code and repeat the ...
Loops Are Fun (You Can Say That Again) 69 import turtle t = turtle.Pen() u t.penup() turtle.bgcolor("black") The first few lines ...
70 Chapter 4 to this position and heading after finishing each small spiral in order to maintain the shape of the big spiral. If ...
Loops Are Fun (You Can Say That Again) 71 the turtle to the heading we stored at x before going on to the next part of the big s ...
72 Chapter 4 You’ll notice the one drawback to nested loops while you’re waiting for this program to run: the shapes shown in Fi ...
Loops Are Fun (You Can Say That Again) 73 What You Learned In this chapter, you learned to build your own loops by identify- ing ...
74 Chapter 4 • Give examples of situations in which you would use each type of loop. • Design and modify programs that use ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf