The Python Workbook
Abstract
I believe that computer programming is a skill that is best learned through hands-on
experience. While it is valuable for you to read about programming in textbooks
and watch teachers create programs at the front of classrooms, it is even more
important for you to spend time solving problems that allow you to put the ideas
that you have been introduced to previously into practice.
This book is designed to support and encourage hands-on learning about programming.
It contains 174 exercises, spanning a variety of academic disciplines and
everyday situations, which you can solve using only the material covered in most
introductory Python programming courses. Each exercise that you complete will
strengthen your understanding and enhance your ability to tackle subsequent programming
challenges. I also hope that the connections that these exercises make to
other academic disciplines and everyday life will keep you interested as you
complete them.
Solutions to approximately half of the exercises are provided in the second half
of this book. Most of the solutions include brief annotations that explain the
technique used to solve the problem, or highlight a specific point of Python syntax.
You will find these annotations in shaded boxes, making it easy to distinguish them
from the solution itself.
I hope that you will take the time to compare each of your solutions with mine,
even when you arrive at your solution without encountering any problems. Performing
this comparison may reveal a flaw in your program, or help you become
more familiar with a technique that you could have used to solve the problem more
easily. In some cases, it could also reveal that you have discovered a faster or easier
way to solve the problem than I have. If you become stuck on an exercise, a quick
peek at my solution may help you work through your problem and continue to make
progress without requiring assistance from someone else. Finally, the solutions that
I have provided demonstrate good programming form, including appropriate comments,
meaningful variable names and minimal use of magic numbers. I encourage
you to use good programming form so that your solutions compute the correct result
while also being clear, easy to understand and easy to update in the future.