A Note About The Solutions

Think of a physical math or science textbook. At the end of most chapters, the authors include a set of practice exercises. To help students check their work, the authors also provide answers to those problems. Some books give all of the answers, while others give solutions for just the odd or even problems.

Our online textbook is not so different! In the following pages, you wil find answers to many of the chapter problems. However, due to the nature of the questions, we can’t always provide a clean odd/even pattern.

Chapter Sandboxes

Developers often create a small project called a sandbox. They use the file to test out bits of code, experiment with small ideas, or problem solve. The code in the file isn’t meant to be saved on its own. If a block of code looks promising, the programmer can copy and paste it from their sandbox into a real life project. The next time a new problem or idea pops up, the programmer wipes their sandbox clean and then starts playing.

The answers in this appendix are displayed as code blocks. However, it often helps to see how a solution runs. Each page includes a chapter sandbox. If you want to see a solution in action, just copy the code from the text and paste it into the sandbox.

Tip

Indentation matters! Python isn’t picky about whether you indent by 2 or 3 or 4 spaces, but you MUST be consistent within a code block. One difficulty with copy/pasting code is that the editor might indent lines by a different amount compared to the text. After a paste, be sure to check the indentation. This is especially true if you type some of your own lines into the editor.

You can adjust the amount of indentation by highlighting one or more lines of code and tapping Tab to indent more or Control-Tab (Command-Tab on a Mac) to un-indent.