| Foreword |
|
ix | |
| Preface |
|
x | |
|
|
|
1 | (24) |
|
|
|
1 | (2) |
|
|
|
3 | (1) |
|
What is Computer Science? |
|
|
3 | (2) |
|
|
|
5 | (1) |
|
|
|
6 | (3) |
|
|
|
9 | (5) |
|
|
|
14 | (3) |
|
|
|
17 | (1) |
|
|
|
18 | (2) |
|
|
|
20 | (5) |
|
|
|
25 | (26) |
|
The Software Development Process |
|
|
25 | (1) |
|
Example Program: Temperature Converter |
|
|
26 | (3) |
|
|
|
29 | (2) |
|
|
|
29 | (1) |
|
|
|
30 | (1) |
|
|
|
31 | (2) |
|
|
|
33 | (6) |
|
|
|
33 | (2) |
|
|
|
35 | (1) |
|
|
|
36 | (3) |
|
|
|
39 | (3) |
|
Example Program: Future Value |
|
|
42 | (3) |
|
|
|
45 | (1) |
|
|
|
46 | (5) |
|
|
|
51 | (26) |
|
|
|
51 | (4) |
|
|
|
55 | (3) |
|
Accumulating Results: Factorial |
|
|
58 | (3) |
|
|
|
61 | (3) |
|
Handling Large Numbers: Long Ints |
|
|
64 | (2) |
|
|
|
66 | (2) |
|
|
|
68 | (1) |
|
|
|
69 | (8) |
|
|
|
77 | (46) |
|
|
|
77 | (5) |
|
|
|
82 | (3) |
|
Strings, Lists, and Sequences |
|
|
85 | (2) |
|
|
|
87 | (10) |
|
|
|
87 | (2) |
|
|
|
89 | (1) |
|
|
|
90 | (4) |
|
|
|
94 | (1) |
|
From Encoding to Encryption |
|
|
95 | (2) |
|
Input/Output as String Manipulation |
|
|
97 | (9) |
|
Example Application: Date Conversion |
|
|
97 | (5) |
|
|
|
102 | (2) |
|
|
|
104 | (2) |
|
|
|
106 | (7) |
|
|
|
106 | (1) |
|
|
|
107 | (4) |
|
Example Program: Batch Usernames |
|
|
111 | (1) |
|
Coming Attraction: Objects |
|
|
112 | (1) |
|
|
|
113 | (2) |
|
|
|
115 | (8) |
|
|
|
123 | (42) |
|
|
|
123 | (1) |
|
|
|
124 | (1) |
|
Simple Graphics Programming |
|
|
125 | (4) |
|
|
|
129 | (6) |
|
|
|
135 | (8) |
|
|
|
143 | (3) |
|
|
|
146 | (5) |
|
|
|
146 | (2) |
|
|
|
148 | (3) |
|
Graphics Module Reference |
|
|
151 | (5) |
|
|
|
151 | (1) |
|
|
|
152 | (3) |
|
|
|
155 | (1) |
|
|
|
155 | (1) |
|
|
|
156 | (1) |
|
|
|
156 | (1) |
|
|
|
157 | (8) |
|
|
|
165 | (34) |
|
The Function of Functions |
|
|
165 | (2) |
|
|
|
167 | (4) |
|
Future Value with a Function |
|
|
171 | (2) |
|
Functions and Parameters: The Details |
|
|
173 | (4) |
|
Getting Results from a Function |
|
|
177 | (10) |
|
Functions That Return Values |
|
|
177 | (4) |
|
Functions that Modify Parameters |
|
|
181 | (6) |
|
Functions and Program Structure |
|
|
187 | (4) |
|
|
|
191 | (1) |
|
|
|
191 | (8) |
|
|
|
199 | (34) |
|
|
|
199 | (7) |
|
Example: Temperature Warnings |
|
|
200 | (2) |
|
Forming Simple Conditions |
|
|
202 | (2) |
|
Example: Conditional Program Execution |
|
|
204 | (2) |
|
|
|
206 | (4) |
|
|
|
210 | (3) |
|
|
|
213 | (4) |
|
Study in Design: Max of Three |
|
|
217 | (8) |
|
Strategy 1: Compare Each to All |
|
|
218 | (2) |
|
Strategy 2: Decision Tree |
|
|
220 | (1) |
|
Strategy 3: Sequential Processing |
|
|
221 | (2) |
|
|
|
223 | (1) |
|
|
|
224 | (1) |
|
|
|
225 | (1) |
|
|
|
225 | (8) |
|
Loop Structures and Booleans |
|
|
233 | (32) |
|
For Loops: A Quick Review |
|
|
233 | (2) |
|
|
|
235 | (2) |
|
|
|
237 | (9) |
|
|
|
237 | (2) |
|
|
|
239 | (3) |
|
|
|
242 | (2) |
|
|
|
244 | (2) |
|
|
|
246 | (5) |
|
|
|
246 | (4) |
|
|
|
250 | (1) |
|
|
|
251 | (7) |
|
|
|
251 | (3) |
|
|
|
254 | (1) |
|
Boolean Expressions as Decisions |
|
|
254 | (4) |
|
|
|
258 | (1) |
|
|
|
259 | (6) |
|
|
|
265 | (30) |
|
|
|
265 | (3) |
|
|
|
266 | (1) |
|
Analysis and Specification |
|
|
266 | (2) |
|
|
|
268 | (2) |
|
|
|
270 | (13) |
|
|
|
271 | (2) |
|
|
|
273 | (1) |
|
|
|
273 | (2) |
|
|
|
275 | (2) |
|
|
|
277 | (3) |
|
|
|
280 | (2) |
|
Summary of the Design Process |
|
|
282 | (1) |
|
|
|
283 | (3) |
|
|
|
283 | (2) |
|
|
|
285 | (1) |
|
|
|
286 | (2) |
|
Prototyping and Spiral Development |
|
|
286 | (2) |
|
|
|
288 | (1) |
|
|
|
288 | (1) |
|
|
|
289 | (6) |
|
|
|
295 | (42) |
|
|
|
295 | (1) |
|
Example Program: Cannonball |
|
|
296 | (7) |
|
|
|
296 | (1) |
|
|
|
297 | (4) |
|
|
|
301 | (2) |
|
|
|
303 | (6) |
|
Example: Multi-Sided Dice |
|
|
303 | (4) |
|
Example: The Projectile Class |
|
|
307 | (2) |
|
Data Processing with Class |
|
|
309 | (4) |
|
Objects and Encapsulation |
|
|
313 | (5) |
|
Encapsulating Useful Abstractions |
|
|
313 | (2) |
|
Putting Classes in Modules |
|
|
315 | (1) |
|
|
|
315 | (2) |
|
Working with Multiple Modules |
|
|
317 | (1) |
|
|
|
318 | (10) |
|
Example Program: Dice Roller |
|
|
319 | (1) |
|
|
|
319 | (4) |
|
|
|
323 | (4) |
|
|
|
327 | (1) |
|
|
|
328 | (1) |
|
|
|
329 | (8) |
|
|
|
337 | (48) |
|
Example Problem: Simple Statistics |
|
|
337 | (2) |
|
|
|
339 | (11) |
|
|
|
340 | (1) |
|
|
|
341 | (4) |
|
|
|
345 | (5) |
|
|
|
350 | (3) |
|
Designing with Lists and Classes |
|
|
353 | (6) |
|
Case Study: Python Calculator |
|
|
359 | (8) |
|
A Calculator as an Object |
|
|
359 | (1) |
|
Constructing the Interface |
|
|
360 | (3) |
|
|
|
363 | (4) |
|
Non-Sequential Collections |
|
|
367 | (8) |
|
|
|
367 | (1) |
|
|
|
368 | (2) |
|
Example Program: Word Frequency |
|
|
370 | (5) |
|
|
|
375 | (1) |
|
|
|
376 | (9) |
|
|
|
385 | (40) |
|
|
|
385 | (3) |
|
Case Study: Racquetball Simulation |
|
|
388 | (11) |
|
Candidate Objects and Methods |
|
|
388 | (2) |
|
|
|
390 | (2) |
|
|
|
392 | (3) |
|
|
|
395 | (1) |
|
|
|
396 | (3) |
|
|
|
399 | (18) |
|
|
|
399 | (1) |
|
Identifying Candidate Objects |
|
|
400 | (2) |
|
|
|
402 | (4) |
|
|
|
406 | (3) |
|
|
|
409 | (8) |
|
|
|
417 | (4) |
|
|
|
418 | (1) |
|
|
|
418 | (1) |
|
|
|
419 | (2) |
|
|
|
421 | (1) |
|
|
|
422 | (3) |
|
Algorithm Design and Recursion |
|
|
425 | (44) |
|
|
|
426 | (5) |
|
A Simple Searching Problem |
|
|
426 | (1) |
|
Strategy 1: Linear Search |
|
|
427 | (1) |
|
Strategy 2: Binary Search |
|
|
428 | (1) |
|
|
|
429 | (2) |
|
Recursive Problem-Solving |
|
|
431 | (12) |
|
|
|
432 | (2) |
|
|
|
434 | (1) |
|
|
|
435 | (2) |
|
|
|
437 | (1) |
|
Example: Fast Exponentiation |
|
|
438 | (1) |
|
|
|
439 | (1) |
|
|
|
440 | (3) |
|
|
|
443 | (7) |
|
Naive Sorting: Selection Sort |
|
|
443 | (2) |
|
Divide and Conquer: Merge Sort |
|
|
445 | (2) |
|
|
|
447 | (3) |
|
|
|
450 | (9) |
|
|
|
450 | (5) |
|
|
|
455 | (4) |
|
|
|
459 | (1) |
|
|
|
459 | (1) |
|
|
|
460 | (9) |
| Appendix A Python Quick Reference |
|
469 | (10) |
| Appendix B Using Python and IDLE |
|
479 | (12) |
| Appendix C Glossary |
|
491 | (12) |
| Index |
|
503 | |