Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
Loops Are Fun (You Can Say That Again) 75 #2: A Spiral of Family Spirals Wouldn’t it be cool to draw a spiral of spirals of your ...
...
5 Conditions (What if?) In addition to speed and accuracy, one quality that makes computers powerful is their ability to evalu- ...
78 Chapter 5 In each of these cases, the computer checks a set of conditions: Is the temperature too cold? Is there something in ...
Conditions (What If?) 79 bring an umbrella; otherwise, you don’t. In this chapter, we’ll learn how to program the computer to ma ...
80 Chapter 5 equal to” uses two equal signs together, ==, to distinguish it from the assignment operator, which is a single equa ...
Conditions (What If?) 81 Figure 5-2: If you answer y to the question in IfSpiral.py, you’ll see a spiral like this one. If you e ...
82 Chapter 5 they equal? Each comparison you make using a comparison opera- tor is a condition that will evaluate to True or Fal ...
Conditions (What If?) 83 The operator that tests to see if two values are not equal is !=, an exclamation point followed by the ...
84 Chapter 5 are built-in constant values in Python. Python will not understand if you type True as true without the capital T, ...
Conditions (What If?) 85 Figure 5-4: I’m old enough to drive in the United States, but my five-year-old son isn’t. The only catc ...
86 Chapter 5 only makes the code shorter and easier to read, but it also helps prevent coding errors in the two conditions. For ...
Conditions (What If?) 87 w for x in range(number): x if shape == 'r': # User selected rosette y t.circle(100) z else: # Default ...
88 Chapter 5 Even or Odd? The if-else statement can test more than user input. We can use it to alternate shapes, like in Figure ...
Conditions (What If?) 89 Ask the user for the number of sides, default to 4 sides = int(turtle.numinput("Number of sides", "How ...
90 Chapter 5 Figure 5-6: Two runs of our RosettesAndPolygons.py program with user inputs of 4 sides (top) and 5 sides (bottom) ...
Conditions (What If?) 91 Notice that when we use an even number of sides, the alter- nating shapes form separate legs of the spi ...
92 Chapter 5 At u, we ask the user for a numeric grade from 0 to 100 with an input() prompt, convert it to a number with the eva ...
Conditions (What If?) 93 The lower() function changed the capital Y and capital S in Yes, Sir to lowercase, leaving the rest of ...
94 Chapter 5 Now we’re testing if either of two conditions is True. If either is True, the user gets to see the spiral. Notice t ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf