Table of Contents
   Prefacep. xiii
   Acknowledgmentsp. xix
   About this bookp. xxi
   Getting Startedp. 1
      Installing Pythonp. 1
      Starting Python with IDLEp. 2
      Instructions, pleasep. 3
      Interacting with Pythonp. 5
      Time to programp. 7
      Running your first programp. 8
      If something goes wrongp. 9
      Your second programp. 11
   Remember This-Memory and Variablesp. 14
      Input, processing, outputp. 14
      Namesp. 16
      What's in a name?p. 20
      Numbers and stringsp. 21
      How "variable" are they?p. 22
      The new mep. 23
   Basic Mathp. 26
      The four basic operationsp. 27
      Operatorsp. 28
      Order of operationsp. 29
      Two more operatorsp. 30
      Really big and really smallp. 33
   Types of Datap. 38
      Changing typesp. 38
      Getting more information: type()p. 41
      Type-conversion errorsp. 42
      Using type conversionsp. 42
   Inputp. 44
      raw_input ()p. 45
      The print command and the commap. 45
      Inputting numbersp. 47
      Input from the Webp. 49
   GUIs-Graphical User Interfacesp. 52
      What's a GUI?p. 52
      Our first GUIp. 53
      GUI inputp. 54
      Pick your flavorp. 55
      The number-guessing game ... againp. 59
      Other GUI piecesp. 60
   Decisions, Decisionsp. 62
      Testing, testingp. 62
      Indentingp. 65
      Am I seeing double?p. 65
      Other kinds of testsp. 66
      What happens if the test is false?p. 67
      Testing for more than one conditionp. 69
      Using "and"p. 69
      Using "or"p. 70
      Using "not"p. 70
   Loop the Loopp. 74
      Counting loopsp. 75
      Using a counting loopp. 77
      A shortcut-range ()p. 78
      A matter of style-loop variable namesp. 80
      Counting by stepsp. 82
      Counting without numbersp. 84
      While we're on the subject ...p. 84
      Bailing out of a loop-break and continuep. 85
   Just for You-Commentsp. 89
      Adding commentsp. 89
      Single-line commentsp. 90
      End-of-line commentsp. 90
      Multiline commentsp. 90
      Commenting stylep. 91
      Commenting outp. 92
   Game Timep. 94
      Skierp. 94
   Nested and Variable Loopsp. 99
      Nested loopsp. 99
      Variable loopsp. 101
      Variable nested loopsp. 102
      Even more variable nested loopsp. 103
      Using nested loopsp. 105
   Collecting Things Together-Listsp. 112
      What's a list?p. 112
      Creating a listp. 113
      Adding things to a listp. 113
      What's the dot?p. 114
      Lists can hold anythingp. 114
      Getting items from a listp. 115
      "Slicing" a listp. 116
      Modifying itemsp. 118
      Other ways of adding to a listp. 118
      Deleting from a listp. 120
      Searching a listp. 121
      Looping through a listp. 122
      Sorting listsp. 123
      Mutable and immutablep. 126
      Lists of lists: tables of datap. 126
   Functionsp. 131
      Functions-the building blocksp. 131
      Calling a functionp. 133
      Passing arguments to a functionp. 134
      Functions with more than one argumentp. 137
      Functions that return a valuep. 139
      Variable scopep. 140
      Forcing a globalp. 143
      A bit of advice on naming variablesp. 144
   Objectsp. 146
      Objects in the real worldp. 147
      Objects in Pythonp. 147
      Object = attributes + methodsp. 148
      What's the dot?p. 149
      Creating objectsp. 149
      An example class-HotDogp. 154
      Hiding the datap. 159
      Polymorphism and inheritancep. 159
      Thinking aheadp. 162
   Modulesp. 164
      What's a module?p. 164
      Why use modules?p. 164
      Buckets of blocksp. 165
      How do we create modules?p. 165
      How do we use modules?p. 166
      Namespacesp. 167
      Standard modulesp. 170
   Graphicsp. 174
      Getting some help-Pygamep. 174
      A Pygame windowp. 175
      Drawing in the windowp. 178
      Individual pixelsp. 186
      Imagesp. 190
      Let's get moving!p. 192
      Animationp. 193
      Smoother animationp. 194
      Bouncing the ballp. 196
      Wrapping the ballp. 198
   Sprites and Collision Detectionp. 202
      Spritesp. 202
      Bump! Collision detectionp. 208
      Counting timep. 212
   A New Kind of Input-Eventsp. 217
      Eventsp. 217
      Keyboard eventsp. 219
      Mouse eventsp. 223
      Timer eventsp. 225
      Time for another game-PyPongp. 227
   Soundp. 239
      More help from Pygame-mixerp. 239
      Making sounds versus playing soundsp. 240
      Playing soundsp. 240
      Controlling volumep. 243
      Repeating musicp. 245
      Adding sounds to PyPongp. 245
      More wacky soundsp. 246
      Adding music to PyPongp. 250
   More GUIsp. 254
      Working with PythonCardp. 254
      Componentsp. 255
      Making our GUI do somethingp. 258
      The return of event handlersp. 259
      Moving the buttonp. 260
      More useful GUIsp. 260
      TempGUIp. 261
      What's on the menu?p. 266
   Print Formatting and Stringsp. 273
      New linesp. 274
      Horizontal spacing-tabsp. 275
      Inserting variables in stringsp. 277
      Number formattingp. 278
      Strings 'n' thingsp. 282
   File Input and Outputp. 290
      What's a file?p. 291
      Filenamesp. 291
      File locationsp. 292
      Opening a filep. 296
      Reading a filep. 297
      Text files and binary filesp. 299
      Writing to a filep. 300
      Saving your stuff in files: picklep. 303
      Game time again-Hangmanp. 305
   Take a Chance-Randomnessp. 313
      What's randomness?p. 313
      Rolling the dicep. 314
      Creating a deck of cardsp. 319
      Crazy Eightsp. 323
   Computer Simulationsp. 336
      Modeling the real worldp. 336
      Lunar Landerp. 337
      Keeping timep. 342
      Time objectsp. 343
      Saving time to a filep. 347
      Virtual Petp. 349
   What's Next?p. 358
      General programmingp. 358
      Pythonp. 359
      Game programming and Pygamep. 359
      Other Python stuffp. 360
      Look aroundp. 362
   Variable Naming Rulesp. 363
   Answers to Self-Test Questionsp. 365
      Getting Startedp. 365
      Remember This-Memory and Variablesp. 366
      Basic Mathp. 367
      Types of Datap. 368
      Inputp. 369
      GUIs-Graphical User Interfacesp. 371
      Decisions, Decisionsp. 372
      Loop the Loopp. 374
      Just for You-Commentsp. 375
      Game Timep. 376
      Nested and Variable Loopsp. 376
      Collecting Things Together-Listsp. 377
      Functionsp. 379
      Objectsp. 380
      Modulesp. 382
      Graphicsp. 383
      Sprites and Collision Detectionp. 385
      A New Kind of Input-Eventsp. 385
      Soundp. 386
      More GUIsp. 386
      Print Formatting and Stringsp. 387
      File Input and Outputp. 388
      Take a Chance-Randomnessp. 390
      Computer Simulationsp. 391
   Indexp. 393