Programming can be an intimidating topic. When people ask me if they’re learning the “right” way or reading the “right” books, I remind them that programming is a skill. Like all skills, you get better by doing it and challenging yourself. Calm seas don’t make skilled sailors.
I wrote the original Automate the Boring Stuff with Python book over 10 years ago, and since then it has sold over a half-million copies. That book teaches the syntax and third-party packages of the Python programming language, but you probably picked up this workbook because you know that the world of programming can’t be captured by any single text. In these pages, you’ll find additional practice questions and projects to challenge your ability to automate boring tasks with code.
The 24 chapters in this book correspond to the 24 chapters of Automate the Boring Stuff with Python, 3rd edition. You can work through the two books simultaneously or use this workbook if you’ve already read the original text and want to assess how well you’ve retained that knowledge.
But even if you haven’t read the source text, you’ll find this workbook useful, especially if you fall into any of the following categories:
No matter which group you fall into, I recommend working through the workbook’s problems multiple times to secure your understanding of the underlying ideas. Mastery comes not from obtaining knowledge but from being able to recall knowledge you’ve previously obtained. One way to achieve mastery is through spaced repetition: the practice of answering questions over time, with a focus on the questions you find most difficult. (Flash cards are a common form of spaced repetition studying.) Use this workbook for continuous practice, rather than reading it once and putting it back on the shelf to gather dust.
This book contains questions and practice projects organized in chapters and sections that correspond to those in Automate the Boring Stuff with Python. You’ll find the answers to the questions at the back of the workbook, along with light explanations and complete, runnable solution programs for the practice projects. There are many correct ways to write a program, and yours don’t have to match these solutions exactly. If you’re at a loss as to where to begin with your program, however, you can glance at the solution code before making a renewed attempt.
Here’s a brief rundown of the kinds of questions you’ll encounter in each chapter:
This workbook can be a useful resource for instructors teaching from Automate the Boring Stuff with Python, or other sources. The questions in Chapters 1 through 11 in particular cover the Python language and standard library and can supplement any general Python curriculum.
All of the questions are answered in the back of the workbook, and any student with a copy of the workbook can read these answers. This may be of concern for instructors who want to assign these questions as homework. (Moreover, answers to these straightforward questions are readily found online or can be generated by large language model AIs such as ChatGPT.) Nevertheless, you can use these questions in the classroom or modify them for your own purposes.
The questions use the free-response format, meaning the student must directly provide the answer. They often encourage the student to experiment in the Python interactive shell. For example, a student can answer the question “Does round(4.9) evaluate to the integer 5 or the float 5.0?” by running the code. If the student doesn’t have access to a computer, you can make the questions easier by providing a multiple-choice answer format or an answer bank they can match to a set of questions.
Software development is a large field, and no one can expect to memorize every part of it. It should come as no surprise, then, that programmers have created software to help them program. Search engines and Python’s interactive shell are also great ways to find the information you’re looking for. You should never consider it “cheating” to search for something online. Professional software engineers do it dozens of times a day!
Knowing how to find information online is an important skill, and it requires you to carefully think about what exactly it is you want to know. It’s often much faster to find existing answers online than it is to post your question somewhere and wait hours (or days or weeks!) for a reply.
If you do need to post a question, be specific. When I teach coding online to others, I often get comments like, “My program doesn’t work,” with no other information. It’s hard as an instructor to help in these cases; the comment isn’t even a question! One way to ask thoughtful questions is via rubber duck debugging: Put a rubber duck or some other inanimate object on your desk and explain your problem to it. You can do this out loud, or write your questions in an empty document on your computer. The key is to articulate your thoughts with actual words. Explain to the duck the answers to the following questions:
Programming is not a passive or magical activity: There are real, concrete answers to your questions, but you’ll have to reach for them yourself. Whenever you don’t understand why your program is doing something, remember that the answer always ends up being “The program did that because, well, technically that’s what the code I wrote does.”
Another way to answer your questions is to run some code in the interactive shell. By entering Python instructions at the >>> prompt, you can execute a single instruction and immediately see its result. For example, if you pass 9.9 to the int() function, will it return 9 or 10? What error message will it show if you pass a blank string instead? And if you pass a variable that contains an integer to int(), does it raise an exception or work fine? You don’t need to look up the Python documentation to answer these questions; just enter the code into the interactive shell and find out:
>>> int(9.9) 9 >>> int('') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '' >>> some_variable = 42 >>> int(some_variable) 42
Many of the questions in this book can be answered in this way. If you’re wondering how some code works, the best way to find out is to execute it yourself.
Also note that, even though error messages like ValueError: invalid literal for int() with base 10: '' aren’t very clear, you can copy and paste such messages into an internet search engine to find other people who have encountered the same error, then read their explanations on how to fix it.
When experienced software developers try to help beginners, they commonly give two bits of misguided advice. The first is that beginners should contribute to open source projects as a way to build experience. In reality, open source projects tend to be large, complicated pieces of software, and making meaningful contributions to them is beyond the ability of beginners. Even trying to create a “small feature” or fix a “simple bug” involves learning the entire structure of the project. These projects are often maintained by unpaid volunteers who might not have time to help drop-in, one-off contributors become familiar with the code base.
The second piece of advice is to work on your own projects. While this is a good idea, it doesn’t offer guidance as to what sorts of projects one can make. Beginners often don’t know what’s possible, or what is beyond their capabilities. “Create an operating system” and “create an AI helper” sound cool but are far too complicated for a single individual of any skill level to tackle.
Beginners need guide rails rather than vague advice. Here are my recommendations for coming up with a software project to create:
My other Python books have several such projects. They are short,
simple, and complete examples of basic programs that don’t require a
lot of setup or complex third-party packages:
The solution programs to this book’s practice projects are available in the downloadable resources at https://nostarch.com/automate-workbook. You can use these projects as inspiration for making more elaborate projects of your own.
These simple programs should give you an idea of what’s possible at the beginner level. Testing your Python knowledge and writing code should make you well equipped to continue your programming journey.