Professional Documents
Culture Documents
COMPUTING USING
^l^S^^^^^^^^^^S^^^
M
^.1^L^ gs|*^gs| (s^S^^^^S^^ ^S^^^^ls
M&T
sSSr 'SSf
M
iffy
mlKlkMAm
(*jW>>
(ggu ^SBBfr <ggV
WILLIAM PUNCH
RICHARD ENBODY
Addis on-Wesley
Boston Columbus Indianapolis New York San Francisco Upper Saddle River
.Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto
Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Sinaanm-e Tainei Tokvo
CONTENTS
PREFACE xxi
Why Python? 11
Is Python the Best Language? 12
0.5 What is a
Computer? 13
Computation in Nature 13
Representing Letters 28
Representing Other Data 29
"What Does a Number Represent? 30
How Talk About Quantities of Data
to 31
How Much Data is That? 31
Summary 33
Chapter 1 Beginnings 37
Integer Operators 61
Floating Point Operators 62
Mixed Operations 62
Order of Operations and Parentheses 63
Augmented Assignment Operators: A Shortcut! 64
1.8 Your First Module, Math 66
1.9 Developing an
Algorithm 67
1.10 Conclusion 70
CONTENTS iX
Chapter 2 Control 79
The if Statement 81
Repetition 88
Nesting 129
Computing 136
Summary 138
Exercises 138
Programming Projects 144
Correctness 156
Input 163
Doing the Calculation 166
Summary 171
Exercises 171
Concatenation? 185
Comparison Operators 186
CONTENTS Xi
Summary 218
Exercises 218
Summary 245
Exercises 245
Programming Projects 249
Xii CONTENTS
6.4 Old and New Friends: Range, Split, and Other Functions
and Methods 261
Anagrams 264
Docstrings 328
History 361
What's in a Set? 361
Python Sets 361
XiV CONTENTS
Documents 367
Summary 383
Exercises 383
Summary 413
Exercises 414
Summary 452
Exercises 452
460
11.3 Working with Classes and Instances
Built-in Class and Instance 460
Our First Class 461
Summary 528
Exercises 528
Eating 554
The Tick of the Clock 555
14.6 More on
Exceptions 574
Raise 574
Create Your Own 575
APPENDICES 619
INDEX 657