Downloading and Installing Python
PART I: HITCHIN’ UP YOUR PYTHON WAGON
1
DRAWING POLYGONS WITH THE TURTLE MODULE
Using a for Loop to Draw a Square
Creating Shortcuts with Functions
Using Variables to Draw Shapes
Writing the triangle() Function
2
MAKING TEDIOUS ARITHMETIC FUN WITH LISTS AND LOOPS
Using Operators to Write the average() Function
Using Parentheses with Operators
Accessing Individual Items with List Indices
Accessing Index and Value with enumerate()
Accessing a Range of List Items
Finding Out the Index of an Item
Creating the running_sum Variable
Finding the Average of a List of Numbers
3
GUESSING AND CHECKING WITH CONDITIONALS
Making Decisions with if and else Statements
Using Conditionals to Find Factors
Writing the factors.py Program
Creating a Number-Guessing Game
Making a Random Number Generator
Converting User Input to Integers
Using Conditionals to Check for a Correct Guess
Applying the Number-Guessing Game Logic
Writing the squareRoot() Function
PART 2: RIDING INTO MATH TERRITORY
4
TRANSFORMING AND STORING NUMBERS WITH ALGEBRA
Solving First-Degree Equations
Finding the Formula for First-Degree Equations
Writing the equation() Function
Using print() Instead of return
Solving Higher-Degree Equations
Using quad() to Solve Quadratic Equations
Using plug() to Solve a Cubic Equation
Getting Started with Processing
Creating Your Own Graphing Tool
Using Guess and Check to Find the Roots
5
TRANSFORMING SHAPES WITH GEOMETRY
Specifying Location Using Coordinates
Translating Objects with translate()
Rotating Objects with rotate()
Rotating the Individual Squares
Saving Orientation with pushMatrix() and popMatrix()
Creating an Interactive Rainbow Grid
Adding the Rainbow Color to Objects
Drawing Complex Patterns Using Triangles
Drawing an Equilateral Triangle
Drawing Multiple Rotating Triangles
6
CREATING OSCILLATIONS WITH TRIGONOMETRY
Using Trigonometry for Rotations and Oscillations
Writing Functions to Draw Polygons
Drawing an Equilateral Triangle
Using Python’s Built-in enumerate() Function
Writing the harmonograph Program
Two Pendulums Are Better Than One
Multiplying a Complex Number by i
Multiplying Two Complex Numbers
Writing the magnitude() Function
Writing the mandelbrot() Function
Adding Color to the Mandelbrot Set
8
USING MATRICES FOR COMPUTER GRAPHICS AND SYSTEMS OF EQUATIONS
Order Matters in Matrix Multiplication
Rotating Matrices in Real Time
Solving Systems of Equations with Matrices
PART 3: BLAZING YOUR OWN TRAIL
9
BUILDING OBJECTS WITH CLASSES
Making the Ball Bounce Off the Wall
Making Multiple Balls Without Classes
Creating Objects Using Classes
Writing the Class for the Sheep
Programming Sheep to Move Around
Making the Grass Brown when Eaten
Giving Each Sheep a Random Color
Programming Sheep to Reproduce
Providing an Evolutionary Advantage
10
CREATING FRACTALS USING RECURSION
Writing the factorial() Function
Writing the segment() Function
Putting the Cells into a Matrix
Letting Your CA Grow Automatically
The Elementary Cellular Automaton
12
SOLVING PROBLEMS USING GENETIC ALGORITHMS
Using a Genetic Algorithm to Guess Phrases
Writing the makeList() Function
Testing the makeList() Function
Solving the Traveling Salesperson Problem (TSP)
Writing the calcLength() Method
Testing the calcLength() Method
Applying the Phrase-Guessing Mutation Idea
Mutating Two Numbers in a List