Math Adventures With Python

Math Adventures With Python — page 5
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