L operators mathematical in Python, 20 Leibniz, Gottfried, 127 using, 21 len() (built-in Python function), 34 using with parentheses, 22 lists, xix, 17, 19, 25–30, 34, 35, 234 origin, 62 adding to, 26 for objects, 257, 268, 269 P operating on, 26, 27 removing items from, 27 Papert, Seymour, vi, 4 loops, 3, phrase-guessing program, 248–254 for loop, 7–9 plug() function, 54–55, 60–61 while loop, 251 popMatrix() function, 88, 89, 98, 218, M 222, 223 print() function, xix, 7, 8, 28, 32, Mandelbrot, Benoit, xx Mandelbrot set, xx, 132–140 39, 40, 44–47, 49, 54, 61, map() (built-in Processing function), 171, 176, 250–253 instead of return, 57 160, 162–164, 207, println() function, 136, 137, 261, 212–213, 219, 222 263, 264, 267, 270 matrices, 145–172 Processing adding, 146 drawing a grid, 64–66 multiplying, 147 drawing axes, 66–67 rotation, 160–162 installing, xxiv solving systems of equations plotting points, 69–70 with, 166–172 setting graph dimensions, 63–64 transformations, 154 pushMatrix() function, 88, 98, 218, transposing, 156 222, 223 Mindstorms, 4 modulo operator (%), 40, 193, 266 Q mouseX keyword, 91, 162, 207, 212 quadratic equations, 59–60 N R Nasrudin, 77, 92, 102 New Kind of Science, 231, 242 randint() function, 42, 42, 45–47 noFill() function, 98, 255 random module, 42–47, 181–185, 188, noStroke(), 121, 125, 137, 139, 192, 189, 191, 193–195, 251 216, 237, 244 random.seed() function, 251 number-guessing game, 37, 43–50 range() (built-in Python function), O 7–9, 28, 29, 32, 33, 66 rectMode(), 89, 92, 93, 96, 98 objects recursion, see recursion defining using classes, 182 instantiating, 182, 195 concept, 203 updating, 182 RGB color mode, 65, 91, 139, 185, 190, 215, 216 Richardson, Lewis, 202 roots of an equation, 73, 75 Index 275
rotate() (built–in Processing along a line, 205, 215, 210, function), 83–89, 93, 94, 211, 220 96–100, 107–109, 111, 205, 206, 208, 209, 211, and rotate, 83, 84, 98, 136 215, 221, 222, 223 centering the origin, 65, 82, running sum, 32 83, 85, 92, 93, 96, 111, Russell, Bertrand, 53 116, 164 moving the grid, 82, 111, 112, S 115, 205, 214, 216, 219 shapes, 80, 81, 93 scale factor, 137 Traveling Salesperson Problem school math, xviii (TSP), 254–271 Scientific American, 238 triangles setup() function, 62, 64, 82, 90, 121, rotating triangles sketch, 93–101 with turtles, 13 137, 182, 187, 205, 214, trigonometry, xxi, 103–126, 258 220, 255 True, 24, 31, 38 Shah, Idries, 37, 77 try-except, exception handling with, Sierpinski Triangle, 214–216 233–234 sine, 102, 104–108, 110–112, 114–117, turtle module 120, 126, 160 drawing with, 4–17, 41–43 size() function, 82, 214 history, 4 special right triangle, 94, 95 importing, 4 spiral of squares, 16 methods, 17 Spirograph program, 116–120 squareRoot() function, 49–50 V strings, 23, 26, 31, 249 stroke() (built-in Processing variables function) assigning value to, 207 in a grid, 65–68, 71, 72, 119, definition, 11 152–153, 159–160 use in functions, 11–12 of a curve, 72, 116, 119, 122–125 of a shape, 101, 111, 154, 157– vertex() function, 106, 107, 108, 126 158, 163–165, 185, 222, 223, 258, 263 W strokeWeight() function drawing a grid, 66, 68, 71, 152 while loop, 251 setting the thickness of lines, Wolfram, Stephen, 231, 242 64–65, 153, 163, 164, 220, Wright, Steven, 201, 225 222, 223, 258, 263 sum() (built-in Python function), 34 summation, 32 T text() function, 256 translate(), (built-in Processing function), 64, 68, 89, 96, 98 276 Index
Math Adventures with Python is set in ITC New Baskerville,TheSansMono C ondensed, Dogma, and Housearama Kingpin.
Resources Visit https://nostarch.com/mathadventures/ for resources, errata, and more information. More Smart Books from no starch! Teach Your Kids to Code Doing Math With Python Python PLayground A Parent-Friendly Guide to Python Use Programming to Explore Algebra, Geeky Projects for the Curious Programming Statistics, Calculus, and More! Programmer by bryson payne by amit saha by mahesh venkitachalam april 2015, 336 pp., $29.95 august 2015, 264 pp., $29.95 october 2015, 352 pp., $29.95 isbn 978-1-59327-614-0 isbn 978-1-59327-640-9 isbn 978-1-59327-604-1 full color Automate the Boring Mission Python Python Crash Course Stuff with Python Code a Space Adventure Game! A Hands-On, Project-Based Practical Programming for Total Introduction to Programming Beginners by sean mcmanus by eric matthes by al sweigart october 2018, 280 pp., $29.95 november 2015, 560 pp., $39.95 april 2015, 504 pp., $29.95 isbn 978-1-59327-857-1 isbn 978-1-59327-603-4 isbn 978-1-59327-599-0 full color 1.800.420.7240 or 1.415.863.9900 | [email protected] | www.nostarch.com
MAKE MATH COVERS COME ALIVE PYTHON 3 WITH PYTHON Math Adventures with Python will show you how to • Use recursion to create fractals like the Koch harness the power of programming to keep math snowflake and the Sierpinski triangle relevant and fun. With the aid of the Python program- ming language, you’ll learn how to visualize solutions • Generate virtual sheep that graze on grass and to a range of math problems as you use code to explore multiply autonomously key mathematical concepts like algebra, trigonometry, matrices, and cellular automata. • Crack secret codes using genetic algorithms Once you’ve learned programming basics like loops As you work through the book’s numerous examples and variables, you’ll write your own programs to solve and increasingly challenging exercises, you’ll code equations quickly, make cool things like an interactive your own solutions, create beautiful visualizations, rainbow grid, and automate tedious tasks like factoring and see just how much more fun math can be! numbers and finding square roots. You’ll learn how to write functions to draw and manipulate shapes, create ABOUT THE AUTHOR oscillating sine waves, and solve equations graphically. Peter Farrell is a math and computer science teacher You’ll also learn how to: with a passion for customizing (”hacking”) math education and learning with technology. He lives in • Draw and transform 2D and 3D graphics with the San Francisco Bay Area with his wife and children. matrices • Make colorful designs like the Mandelbrot and Julia sets with complex numbers THE FINEST IN GEEK ENTERTAINMENT™ w w w.nostarch.com $29.95 ($39.95 CDN) SHELVE IN: PROGRAMMING LANGUAGES/PYTHON
Search
Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306