## Book description

Doing Math with Python shows you how to use Python to delve into high school—level math topics like statistics, geometry, probability, and calculus. You'll start with simple projects, like a factoring program and a quadratic-equation solver, and then create more complex projects once you've gotten the hang of things.

Along the way, you'll discover new ways to explore math and gain valuable programming skills that you'll use throughout your study of math and computer science. Learn how to:

• Describe your data with statistics, and visualize it with line graphs, bar charts, and scatter plots
• Explore set theory and probability with programs for coin flips, dicing, and other games of chance
• Solve algebra problems using Python's symbolic math functions
• Draw geometric shapes and explore fractals like the Barnsley fern, the Sierpinski triangle, and the Mandelbrot set
• Write programs to find derivatives and integrate functions
Creative coding challenges and applied examples help you see how you can put your new math and coding skills into practice. You'll write an inequality solver, plot gravity's effect on how far a bullet will travel, shuffle a deck of cards, estimate the area of a circle by throwing 100,000 "darts" at a board, explore the relationship between the Fibonacci sequence and the golden ratio, and more.

Whether you're interested in math but have yet to dip into programming or you're a teacher looking to bring programming into the classroom, you'll find that Python makes programming easy and practical. Let Python handle the grunt work while you focus on the math.

## Publisher resources

View/Submit Errata

1. Cover Page
2. Title Page
4. Dedication
5. Brief Contents
6. Contents in Detail
7. Acknowledgments
8. Introduction
9. Chapter 1: Working with Numbers
1. Basic Mathematical Operations
2. Labels: Attaching Names to Numbers
3. Different Kinds of Numbers
4. Getting User Input
5. Writing Programs That Do the Math for You
6. What You Learned
7. Programming Challenges
10. Chapter 2: Visualizing Data with Graphs
1. Understanding the Cartesian Coordinate Plane
2. Working with Lists and Tuples
3. Creating Graphs with Matplotlib
1. Marking Points on Your Graph
2. Graphing the Average Annual Temperature in New York City
3. Comparing the Monthly Temperature Trends of New York City
4. Customizing Graphs
5. Saving the Plots
4. Plotting with Formulas
1. Newton’s Law of Universal Gravitation
2. Projectile Motion
5. What You Learned
6. Programming Challenges
11. Chapter 3: Describing Data with Statistics
1. Finding the Mean
2. Finding the Median
3. Finding the Mode and Creating a Frequency Table
4. Measuring the Dispersion
5. Calculating the Correlation Between Two Data Sets
6. Scatter Plots
8. What You Learned
9. Programming Challenges
12. Chapter 4: Algebra and Symbolic Math with SymPy
1. Defining Symbols and Symbolic Operations
2. Working with Expressions
1. Factorizing and Expanding Expressions
2. Pretty Printing
3. Substituting in Values
4. Converting Strings to Mathematical Expressions
3. Solving Equations
4. Plotting Using SymPy
5. What You Learned
6. Programming Challenges
1. #1: Factor Finder
2. #2: Graphical Equation Solver
3. #3: Summing a Series
4. #4: Solving Single-Variable Inequalities
13. Chapter 5: Playing with Sets and Probability
1. What’s a Set?
1. Set Construction
2. Subsets, Supersets, and Power Sets
3. Set Operations
2. Probability
1. Probability of Event A or Event B
2. Probability of Event A and Event B
3. Generating Random Numbers
4. Nonuniform Random Numbers
3. What You Learned
4. Programming Challenges
14. Chapter 6: Drawing Geometric Shapes and Fractals
1. Drawing Geometric Shapes with Matplotlib’s Patches
2. Drawing Fractals
3. What You Learned
4. Programming Challenges
1. #1: Packing Circles into a Square
2. #2: Drawing the Sierpiński Triangle
3. #3: Exploring Hénon’s Function
4. #4: Drawing the Mandelbrot Set
15. Chapter 7: Solving Calculus Problems
1. What Is a Function?
2. Assumptions in SymPy
3. Finding the Limit of Functions
4. Finding the Derivative of Functions
5. Higher-Order Derivatives and Finding the Maxima and Minima
6. Finding the Global Maximum Using Gradient Ascent
7. Finding the Integrals of Functions
8. Probability Density Functions
9. What You Learned
10. Programming Challenges
16. Afterword
1. Things to Explore Next
2. Getting Help
3. Conclusion
17. Appendix A: Software Installation
1. Microsoft Windows
2. Linux
3. Mac OS X
18. Appendix B: Overview of Python Topics
1. if __name__ == '__main__'
2. List Comprehensions
3. Dictionary Data Structure
4. Multiple Return Values
5. Exception Handling