Teach Your Kids To Code: A Parent-friendly Guide to Python Programming
Conditions (What If?) 95 s cret Messages e Now that we understand how to use conditions, we’re going to learn to encode and deco ...
96 Chapter 5 If we can write a program that looks at each letter in a secret message, then encodes that letter by shifting it 13 ...
Conditions (What If?) 97 And you can check whether a character is a lowercase letter with the islower() function: 'P'.islower ...
98 Chapter 5 Table 5-3: Numeric Values for Standard ASCII Characters Value Symbol Description Value Symbol Description 32 Space ...
Conditions (What If?) 99 The Python function to turn a character into its ASCII num- ber value is ord(): >>> ord('A') 6 ...
100 Chapter 5 in which we’ll store our encoded message, letter by letter. The for loop at w makes use of the fact that Python tr ...
Conditions (What If?) 101 What You Learned In this chapter, you learned how to program a computer to make decisions based on con ...
102 Chapter 5 • Test a variable to see if it is odd or even using the modulo operator, %. • Write if-elif-else statements ...
Conditions (What If?) 103 To decode a message sent with a different key (let’s use 5 as a key value, so A becomes F, B becomes G ...
...
6 Random Fun and Games: Go ahead, take a Chance! In Chapter 5, we programmed the computer to make decisions based on conditions. ...
106 Chapter 6 The common element in these games is the idea of randomness. We want the computer to pick a number at random betwe ...
Random Fun and Games: Go Ahead, Take a Chance! 107 a lowest number and a highest number in the parentheses will tell randint() w ...
108 Chapter 6 At w, we ask the user for a guess between 1 and 10, evalu- ate the number, and store it in the variable guess. Our ...
Random Fun and Games: Go Ahead, Take a Chance! 109 If players learn to use this strategy, they can guess a number between 1 and ...
110 Chapter 6 Think about how you could write a program like the one that created Figure 6-2. You know almost all of the tricks ...
Random Fun and Games: Go Ahead, Take a Chance! 111 Getting Coordinated One remaining problem is how to get the spirals to spread ...
112 Chapter 6 To get to the point in the lower right, (3, –3), we go back to the origin and then move right 3 spaces or units. T ...
Random Fun and Games: Go Ahead, Take a Chance! 113 How Big Is Our Canvas? Now that we know how to position spirals at random loc ...
114 Chapter 6 the left of the origin. The range of x-coordinate values would be from –480 (left 480 pixels from the origin) to + ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf