Contents in Detail acknowledgments xv introduction xvii The Problem with School Math xviii About This Book xx Who Should Use This Book xxi What's in This Book xxi Downloading and Installing Python xxii Starting IDLE xxiii Installing Processing xxiii Part i Hitchin Up Your Python Wagon 1 3 Drawing Polygons with the turtle module Python’s turtle Module 4 Importing the turtle Module 4 Moving Your Turtle 5 Changing Directions 6 Repeating Code with Loops 7 Using the for Loop 7 Using a for Loop to Draw a Square 9 Creating Shortcuts with Functions 9 Using Variables to Draw Shapes 11 Using Variables in Functions 11 Variable Errors 12 Equilateral Triangles 13 Writing the triangle Function 13 Making Variables Vary 14 Summary 17
2 Making tedious arithmetic Fun with lists and loops 19 Basic Operators 20 Operating on Variables 20 Using Operators to Write the average Function 21 Mind the Order of Operations 21 Using Parentheses with Operators 22 Data Types in Python 22 Integers and Floats 22 Strings 23 Booleans 24 Checking Data Types 25 Using Lists to Store Values 25 Adding Items to a List 26 Operating on Lists 26 Removing Items from a List 27 Using Lists in Loops 27 Accessing Individual Items with List Indices 28 Accessing Index and Value with enumerate 29 Indices Start at Zero 29 Accessing a Range of List Items 30 Finding Out the Index of an Item 30 Strings Use Indices Too 31 Summation 32 Creating the running_sum Variable 32 Writing the mySum Function 33 Finding the Average of a List of Numbers 34 Summary 35 3 Guessing and Checking with Conditionals 37 Comparison Operators 38 Making Decisions with if and else Statements 38 Using Conditionals to Find Factors 39 Writing the factors py Program 40 The Wandering Turtle 41 Creating a Number-Guessing Game 43 Making a Random Number Generator 44 Taking User Input 44 Converting User Input to Integers 45 Using Conditionals to Check for a Correct Guess 45 Using a Loop to Guess Again 46 Tips for Guessing 47 Finding Square Roots 48 Applying the Number-Guessing Game Logic 48 Writing the squareRoot Function 49 Summary 50 Contents in Detail
Part 2 Riding into Math territory 4 transforming and storing numbers with algebra 53 Solving First-Degree Equations 54 Finding the Formula for First-Degree Equations 55 Writing the equation Function 56 Using print Instead of return 57 Solving Higher-Degree Equations 58 Using quad to Solve Quadratic Equations 59 Using plug to Solve a Cubic Equation 60 Solving Equations Graphically 61 Getting Started with Processing 61 Creating Your Own Graphing Tool 63 Graphing an Equation 69 Using Guess and Check to Find the Roots 73 Writing the guess Function 73 Summary 75 5 transforming shapes with Geometry 77 Drawing a Circle 78 Specifying Location Using Coordinates 79 Transformation Functions 80 Translating Objects with translate 80 Rotating Objects with rotate 83 Drawing a Circle of Circles 84 Drawing a Circle of Squares 85 Animating Objects 86 Creating the t Variable 86 Rotating the Individual Squares 87 Saving Orientation with pushMatrix and popMatrix 88 Rotating Around the Center 89 Creating an Interactive Rainbow Grid 89 Drawing a Grid of Objects 90 Adding the Rainbow Color to Objects 91 Drawing Complex Patterns Using Triangles 93 A 30-60-90 Triangle 94 Drawing an Equilateral Triangle 96 Drawing Multiple Rotating Triangles 98 Phase-Shifting the Rotation 99 Finalizing the Design 100 Summary 102 Contents in Detail