| |
| |
Preface | |
| |
| |
Acknowledgments | |
| |
| |
About this book | |
| |
| |
| |
Getting Started | |
| |
| |
Installing Python | |
| |
| |
Starting Python with IDLE | |
| |
| |
Instructions, please | |
| |
| |
Interacting with Python | |
| |
| |
Time to program | |
| |
| |
Running your first program | |
| |
| |
If something goes wrong | |
| |
| |
Your second program | |
| |
| |
| |
Remember This-Memory and Variables | |
| |
| |
Input, processing, output | |
| |
| |
Names | |
| |
| |
What's in a name? | |
| |
| |
Numbers and strings | |
| |
| |
How "variable" are they? | |
| |
| |
The new me | |
| |
| |
| |
Basic Math | |
| |
| |
The four basic operations | |
| |
| |
Operators | |
| |
| |
Order of operations | |
| |
| |
Two more operators | |
| |
| |
Really big and really small | |
| |
| |
| |
Types of Data | |
| |
| |
Changing types | |
| |
| |
Getting more information: type() | |
| |
| |
Type-conversion errors | |
| |
| |
Using type conversions | |
| |
| |
| |
Input | |
| |
| |
raw_input () | |
| |
| |
The print command and the comma | |
| |
| |
Inputting numbers | |
| |
| |
Input from the Web | |
| |
| |
| |
GUIs-Graphical User Interfaces | |
| |
| |
What's a GUI? | |
| |
| |
Our first GUI | |
| |
| |
GUI input | |
| |
| |
Pick your flavor | |
| |
| |
The number-guessing game ... again | |
| |
| |
Other GUI pieces | |
| |
| |
| |
Decisions, Decisions | |
| |
| |
Testing, testing | |
| |
| |
Indenting | |
| |
| |
Am I seeing double? | |
| |
| |
Other kinds of tests | |
| |
| |
What happens if the test is false? | |
| |
| |
Testing for more than one condition | |
| |
| |
Using "and" | |
| |
| |
Using "or" | |
| |
| |
Using "not" | |
| |
| |
| |
Loop the Loop | |
| |
| |
Counting loops | |
| |
| |
Using a counting loop | |
| |
| |
A shortcut-range () | |
| |
| |
A matter of style-loop variable names | |
| |
| |
Counting by steps | |
| |
| |
Counting without numbers | |
| |
| |
While we're on the subject ... | |
| |
| |
Bailing out of a loop-break and continue | |
| |
| |
| |
Just for You-Comments | |
| |
| |
Adding comments | |
| |
| |
Single-line comments | |
| |
| |
End-of-line comments | |
| |
| |
Multiline comments | |
| |
| |
Commenting style | |
| |
| |
Commenting out | |
| |
| |
| |
Game Time | |
| |
| |
Skier | |
| |
| |
| |
Nested and Variable Loops | |
| |
| |
Nested loops | |
| |
| |
Variable loops | |
| |
| |
Variable nested loops | |
| |
| |
Even more variable nested loops | |
| |
| |
Using nested loops | |
| |
| |
| |
Collecting Things Together-Lists | |
| |
| |
What's a list? | |
| |
| |
Creating a list | |
| |
| |
Adding things to a list | |
| |
| |
What's the dot? | |
| |
| |
Lists can hold anything | |
| |
| |
Getting items from a list | |
| |
| |
"Slicing" a list | |
| |
| |
Modifying items | |
| |
| |
Other ways of adding to a list | |
| |
| |
Deleting from a list | |
| |
| |
Searching a list | |
| |
| |
Looping through a list | |
| |
| |
Sorting lists | |
| |
| |
Mutable and immutable | |
| |
| |
Lists of lists: tables of data | |
| |
| |
| |
Functions | |
| |
| |
Functions-the building blocks | |
| |
| |
Calling a function | |
| |
| |
Passing arguments to a function | |
| |
| |
Functions with more than one argument | |
| |
| |
Functions that return a value | |
| |
| |
Variable scope | |
| |
| |
Forcing a global | |
| |
| |
A bit of advice on naming variables | |
| |
| |
| |
Objects | |
| |
| |
Objects in the real world | |
| |
| |
Objects in Python | |
| |
| |
Object = attributes + methods | |
| |
| |
What's the dot? | |
| |
| |
Creating objects | |
| |
| |
An example class-HotDog | |
| |
| |
Hiding the data | |
| |
| |
Polymorphism and inheritance | |
| |
| |
Thinking ahead | |
| |
| |
| |
Modules | |
| |
| |
What's a module? | |
| |
| |
Why use modules? | |
| |
| |
Buckets of blocks | |
| |
| |
How do we create modules? | |
| |
| |
How do we use modules? | |
| |
| |
Namespaces | |
| |
| |
Standard modules | |
| |
| |
| |
Graphics | |
| |
| |
Getting some help-Pygame | |
| |
| |
A Pygame window | |
| |
| |
Drawing in the window | |
| |
| |
Individual pixels | |
| |
| |
Images | |
| |
| |
Let's get moving! | |
| |
| |
Animation | |
| |
| |
Smoother animation | |
| |
| |
Bouncing the ball | |
| |
| |
Wrapping the ball | |
| |
| |
| |
Sprites and Collision Detection | |
| |
| |
Sprites | |
| |
| |
Bump! Collision detection | |
| |
| |
Counting time | |
| |
| |
| |
A New Kind of Input-Events | |
| |
| |
Events | |
| |
| |
Keyboard events | |
| |
| |
Mouse events | |
| |
| |
Timer events | |
| |
| |
Time for another game-PyPong | |
| |
| |
| |
Sound | |
| |
| |
More help from Pygame-mixer | |
| |
| |
Making sounds versus playing sounds | |
| |
| |
Playing sounds | |
| |
| |
Controlling volume | |
| |
| |
Repeating music | |
| |
| |
Adding sounds to PyPong | |
| |
| |
More wacky sounds | |
| |
| |
Adding music to PyPong | |
| |
| |
| |
More GUIs | |
| |
| |
Working with PythonCard | |
| |
| |
Components | |
| |
| |
Making our GUI do something | |
| |
| |
The return of event handlers | |
| |
| |
Moving the button | |
| |
| |
More useful GUIs | |
| |
| |
TempGUI | |
| |
| |
What's on the menu? | |
| |
| |
| |
Print Formatting and Strings | |
| |
| |
New lines | |
| |
| |
Horizontal spacing-tabs | |
| |
| |
Inserting variables in strings | |
| |
| |
Number formatting | |
| |
| |
Strings 'n' things | |
| |
| |
| |
File Input and Output | |
| |
| |
What's a file? | |
| |
| |
Filenames | |
| |
| |
File locations | |
| |
| |
Opening a file | |
| |
| |
Reading a file | |
| |
| |
Text files and binary files | |
| |
| |
Writing to a file | |
| |
| |
Saving your stuff in files: pickle | |
| |
| |
Game time again-Hangman | |
| |
| |
| |
Take a Chance-Randomness | |
| |
| |
What's randomness? | |
| |
| |
Rolling the dice | |
| |
| |
Creating a deck of cards | |
| |
| |
Crazy Eights | |
| |
| |
| |
Computer Simulations | |
| |
| |
Modeling the real world | |
| |
| |
Lunar Lander | |
| |
| |
Keeping time | |
| |
| |
Time objects | |
| |
| |
Saving time to a file | |
| |
| |
Virtual Pet | |
| |
| |
| |
What's Next? | |
| |
| |
General programming | |
| |
| |
Python | |
| |
| |
Game programming and Pygame | |
| |
| |
Other Python stuff | |
| |
| |
Look around | |
| |
| |
| |
Variable Naming Rules | |
| |
| |
Answers to Self-Test Questions | |
| |
| |
| |
Getting Started | |
| |
| |
| |
Remember This-Memory and Variables | |
| |
| |
| |
Basic Math | |
| |
| |
| |
Types of Data | |
| |
| |
| |
Input | |
| |
| |
| |
GUIs-Graphical User Interfaces | |
| |
| |
| |
Decisions, Decisions | |
| |
| |
| |
Loop the Loop | |
| |
| |
| |
Just for You-Comments | |
| |
| |
| |
Game Time | |
| |
| |
| |
Nested and Variable Loops | |
| |
| |
| |
Collecting Things Together-Lists | |
| |
| |
| |
Functions | |
| |
| |
| |
Objects | |
| |
| |
| |
Modules | |
| |
| |
| |
Graphics | |
| |
| |
| |
Sprites and Collision Detection | |
| |
| |
| |
A New Kind of Input-Events | |
| |
| |
| |
Sound | |
| |
| |
| |
More GUIs | |
| |
| |
| |
Print Formatting and Strings | |
| |
| |
| |
File Input and Output | |
| |
| |
| |
Take a Chance-Randomness | |
| |
| |
| |
Computer Simulations | |
| |
| |
Index | |