https://levjj.github.io/thinkcspy/ How to Think Like a Computer Scientist: Interactive Edition Table of ContentsP * 1. General Introduction + 1.1. The Way of the Program + 1.2. Algorithms + 1.3. The Python Programming Language + 1.4. Executing Python in this Book + 1.5. More About Programs + 1.6. What is Debugging? + 1.7. Syntax errors + 1.8. Runtime Errors + 1.9. Semantic Errors + 1.10. Experimental Debugging + 1.11. Formal and Natural Languages + 1.12. A Typical First Program + 1.13. Comments + 1.14. Glossary + 1.15. Exercises * 2. Simple Python Data 1 + 2.1. Variables, Expressions and Statements + 2.2. Values and Data Types + 2.3. Type conversion functions + 2.4. Variables + 2.5. Variable Names and Keywords + 2.6. Statements and Expressions + 2.7. Operators and Operands * 3. Simple Python Data 2 + 3.1. Input + 3.2. Order of Operations + 3.3. Reassignment o 3.3.1. Developing your mental model of How Python Evaluates + 3.4. Updating Variables + 3.5. Glossary + 3.6. Exercises * 4. Booleans and Conditionals + 4.1. Boolean Values and Boolean Expressions + 4.2. Logical operators + 4.3. Precedence of Operators + 4.4. Conditional Execution: Binary Selection + 4.5. Omitting the else Clause: Unary Selection + 4.6. Nested conditionals + 4.7. Chained conditionals + 4.8. Boolean Functions o 4.8.1. More Unit Testing + 4.9. Glossary + 4.10. Exercises * 5. For Loops and Turtle Graphics + 5.1. Hello Little Turtles! + 5.2. Our First Turtle Program + 5.3. Instances -- A Herd of Turtles + 5.4. The for Loop + 5.5. Flow of Execution of the for Loop + 5.6. Iteration Simplifies our Turtle Program + 5.7. The range Function + 5.8. A Few More turtle Methods and Observations + 5.9. Summary of Turtle Methods + 5.10. Glossary + 5.11. Exercises * 6. Strings + 6.1. Strings Revisited + 6.2. A Collection Data Type + 6.3. Operations on Strings + 6.4. Index Operator: Working with the Characters of a String + 6.5. String Methods o 6.5.1. String Format Method + 6.6. Length + 6.7. The Slice Operator + 6.8. String Comparison + 6.9. Strings are Immutable + 6.10. Traversal and the for Loop: By Item + 6.11. Traversal and the for Loop: By Index + 6.12. Traversal and the while Loop + 6.13. The in and not in operators + 6.14. The Accumulator Pattern with Strings + 6.15. Turtles and Strings and L-Systems + 6.16. Looping and Counting + 6.17. A find function + 6.18. Optional parameters + 6.19. Character classification + 6.20. Summary + 6.21. Glossary + 6.22. Exercises * 7. Lists + 7.1. Lists + 7.2. List Values + 7.3. List Length + 7.4. Accessing Elements + 7.5. List Membership + 7.6. Concatenation and Repetition + 7.7. List Slices + 7.8. Lists and for loops + 7.9. Lists are Mutable + 7.10. List Deletion + 7.11. Objects and References + 7.12. Aliasing + 7.13. Cloning Lists + 7.14. Repetition and References + 7.15. List Methods + 7.16. Append versus Concatenate + 7.17. List Comprehensions + 7.18. Nested Lists + 7.19. Strings and Lists + 7.20. list Type Conversion Function * 8. More About Iteration + 8.1. Iteration Revisited + 8.2. The for loop revisited + 8.3. The while Statement + 8.4. Randomly Walking Turtles + 8.5. The 3n + 1 Sequence + 8.6. Newton's Method + 8.7. The Accumulator Pattern Revisited + 8.8. Other uses of while o 8.8.1. Sentinel Values o 8.8.2. Validating Input + 8.9. Algorithms Revisited + 8.10. Glossary + 8.11. Exercises * 9. Debugging Interlude + 9.1. How to be a Successful Programmer + 9.2. How to Avoid Debugging + 9.3. Beginning tips for Debugging + 9.4. Know Your Error Messages o 9.4.1. ParseError o 9.4.2. TypeError o 9.4.3. NameError o 9.4.4. ValueError + 9.5. Programming With Style + 9.6. Summary + 9.7. Exercises * 10. Python Modules + 10.1. Modules and Getting Help + 10.2. More About Using Modules + 10.3. The math module + 10.4. The random module + 10.5. Glossary + 10.6. Exercises * 11. Functions + 11.1. Functions + 11.2. Functions that Return Values + 11.3. Variables and Parameters are Local + 11.4. The Accumulator Pattern o 11.4.1. The General Accumulator Pattern o 11.4.2. A Variation on the Accumulator Pattern + 11.5. Functions can Call Other Functions + 11.6. Flow of Execution Summary + 11.7. Program Development + 11.8. Composition + 11.9. Glossary + 11.10. Exercises * 12. Functions, Side Effects and Tuples + 12.1. Using a Main Function + 12.2. A Turtle Bar Chart + 12.3. Using Lists as Parameters + 12.4. Pure Functions + 12.5. Which is Better? + 12.6. Functions that Produce Lists + 12.7. Tuples and Mutability + 12.8. Tuple Assignment + 12.9. Tuples as Return Values + 12.10. Glossary + 12.11. Exercises * 13. Recursion + 13.1. What Is Recursion? + 13.2. Calculating the Sum of a List of Numbers + 13.3. The Three Laws of Recursion + 13.4. Converting an Integer to a String in Any Base + 13.5. Visualizing Recursion + 13.6. Sierpinski Triangle + 13.7. Glossary + 13.8. Programming Exercises * 14. Dictionaries + 14.1. Dictionaries + 14.2. Dictionary Operations + 14.3. Dictionary Methods + 14.4. Aliasing and Copying + 14.5. Sparse Matrices + 14.6. Glossary + 14.7. Exercises * 15. Classes and Objects + 15.1. Object-oriented programming + 15.2. A change of perspective + 15.3. Objects Revisited + 15.4. User Defined Classes + 15.5. Improving our Constructor + 15.6. Adding Other Methods to our Class + 15.7. Objects as Arguments and Parameters + 15.8. Converting an Object to a String + 15.9. Instances as Return Values + 15.10. Glossary + 15.11. Exercises * 16. Image Processing with Nested Loops and GUI Programming + 16.1. 2-Dimensional Iteration: Image Processing o 16.1.1. The RGB Color Model o 16.1.2. Image Objects o 16.1.3. Image Processing and Nested Iteration + 16.2. Graphical User Interfaces + 16.3. GUI Programming + 16.4. GUI Programming Options + 16.5. TKinter + 16.6. Tkinter Pre-programmed Interfaces + 16.7. Tkinter Custom Interfaces + 16.8. Hello World + 16.9. Tkinter Standard Dialog Boxes o 16.9.1. Messages o 16.9.2. Yes/No Questions o 16.9.3. Single Value Data Entry o 16.9.4. File Chooser o 16.9.5. Color Chooser + 16.10. GUI Widgets + 16.11. Creating Widgets + 16.12. Layout Mangers + 16.13. Specifying Dimensions + 16.14. Place Layout Manager + 16.15. Grid Layout Manager + 16.16. Pack Layout Manager o 16.16.1. Summary + 16.17. Widget Groupings + 16.18. Command Events + 16.19. Hello World Again + 16.20. Other Events + 16.21. Low-Level Event Processing + 16.22. Focus + 16.23. Event Binding + 16.24. Event Descriptors + 16.25. Event Objects + 16.26. Event Processing * 17. Files + 17.1. Working with Data Files + 17.2. Finding a File on your Disk + 17.3. Reading a File + 17.4. Iterating over lines in a file + 17.5. Alternative File Reading Methods + 17.6. Writing Text Files + 17.7. With Statements + 17.8. Glossary + 17.9. Exercises Optional LabsP Labs * Astronomy Animation * Turtle Racing Lab * Drawing a Circle * Lessons from a Triangle * Finally a Circle * Counting Letters * Letter Count Histogram * Approximating the Value of Pi * Python Beyond the Browser * Experimenting With the 3n+1 Sequence * Plotting a sine Wave AppendicesP Appendices * Debugging * Operator precedence table AcknowledgementsP Acknowledgements * Copyright Notice * Preface to the Interactive Edition * Whats the deal with Logging in? * How to Contribute * Acknowledgements * Foreword * Preface to the Third Edition * The Rhodes Local Edition (RLE) * Preface to the First and Second Editions * Contributor List * GNU Free Documentation License * ADDENDUM: How to use this License for your documents Index and SearchP * Index * Search Page About this ProjectP This interactive book is a product of the Runestone Interactive Project at Luther College, led by Brad Miller and David Ranum. There have been many contributors to the project. Our thanks especially to the following: * This book is based on the Original work by: Jeffrey Elkner, Allen B. Downey, and Chris Meyers * Activecode based on Skulpt * Codelens based on Online Python Tutor * Many contributions from the CSLearning4U research group at Georgia Tech. * ACM-SIGCSE for the special projects grant that funded our student Isaac Dontje Lindell for the summer of 2013. * NSF The Runestone Interactive tools are open source and we encourage you to contact us, or grab a copy from GitHub if you would like to use them to write your own resources. The sections of this particular version of the book were arranged by Christopher Schuster for the CMPS5P Introduction to Programming with Python course at University of California, Santa Cruz.