Practical Programming, Third Edition
An Introduction to Computer Science Using Python 3.6
by Paul Gries, Jennifer Campbell, Jason Montojo
Version: P1.0 (December 2017)
Copyright 2017 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
About the Pragmatic Bookshelf
The Pragmatic Bookshelf is an agile publishing company. Were here because we want to improve the lives of developers. We do this by creating timely, practical titles, written by programmers for programmers.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Our ebooks do not contain any Digital Restrictions Management, and have always been DRM-free. We pioneered the beta book concept, where you can purchase and read a book while its still being written, and provide feedback to the author to help make a better book for everyone. Free resources for all purchasers include source code downloads (if applicable), errata and discussion forums, all available on the book's home page at pragprog.com. Were here to make your life easier.
New Book Announcements
Want to keep up on our latest titles and announcements, and occasional special offers? Just create an account on pragprog.com (an email address and a password is all it takes) and select the checkbox to receive newsletters. You can also follow us on twitter as @pragprog.
About Ebook Formats
If you buy directly from pragprog.com, you get ebooks in all available formats for one price. You can synch your ebooks amongst all your devices (including iPhone/iPad, Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And, of course, you can always come back and re-download your books when needed. Ebooks bought from the Amazon Kindle store are subject to Amazon's polices. Limitations in Amazon's file format may cause ebooks to display differently on different devices. For more information, please see our FAQ at pragprog.com/frequently-asked-questions/ebooks. To learn more about this book and access the free resources, go to https://pragprog.com/book/gwpy3, the book's homepage.
Thanks for your continued support,
Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Andy Hunt (Publisher) Janet Furlow (VP of Operations) Brian MacDonald (Managing Editor) Jacquelyn Carter (Supervising Editor) Tammy Coron (Development Editor) Potomac Indexing (Indexing) Liz Welch (Copy Editor) Gilson Graphics (Layout)
For customer support, please contact .
For international rights, please contact .
Table of Contents
Copyright 2018, The Pragmatic Bookshelf.
What Readers Are Saying about Practical Programming
I wish I could go back in time and give this book to my 10-year-old self when I first learned programming! Its so much more engaging, practical, and accessible than the dry introductory programming books that I tried (and often failed) to comprehend as a kid. I love the authors hands-on approach of mixing explanations with code snippets that students can type into the Python prompt.
Philip Guo |
Creator of Online Python Tutor (http://www.pythontutor.com), Assistant Professor, Department of Cognitive Science, UCSD |
Practical Programming delivers just what it promises: a clear, readable, usable introduction to programming for beginners. This isnt just a guide to hacking together programs. The book provides foundations to lifelong programming skills: a crisp, consistent, and visual model of memory and execution and a design recipe that will help readers produce quality software.
Steven Wolfman |
Professor of Teaching, Department of Computer Science, University of British Columbia |
This excellent text reflects the authors many years of experience teaching Python to beginning students. Topics are presented so that each leads naturally to the next, and common novice errors and misconceptions are explicitly addressed. The exercises at the end of each chapter invite interested students to explore computer science and programming language topics.
Kathleen Freeman |
Director of Undergraduate Studies, Department of Computer and Information Science, University of Oregon |
Acknowledgments
This book would be confusing and riddled with errors if it werent for a bunch of awesome people who patiently and carefully read our drafts.
We had a great team of people provide technical reviews for this edition and previous editions: in no particular order, Frank Ruiz, Stefan Turalski, Stephen Wolff, Peter W.A. Wood, Steve Wolfman, Adam Foster, Owen Nelson, Arturo Martnez Peguero, C. Keith Ray, Michael Szamosi, David Gries, Peter Beens, Edward Branley, Paul Holbrook, Kristie Jolliffe, Mike Riley, Sean Stickle, Tim Ottinger, Bill Dudney, Dan Zingaro, and Justin Stanley. We also appreciate all the people who reported errata: your feedback was invaluable.
Greg Wilson started us on this journey when he proposed that we write a textbook, and he was our guide and mentor as we worked together to create the first edition of this book.
Finally, we would like to thank our editor Tammy Coron, who set up a workflow that made the tight timeline possible. Tammy, your gentle nudges kept us on track (squirrel!) and helped us complete this third edition in record time.
Copyright 2018, The Pragmatic Bookshelf.
Preface
This book uses the Python programming language to teach introductory computer science topics and a handful of useful applications. Youll certainly learn a fair amount of Python as you work through this book, but along the way youll also learn about issues that every programmer needs to know: ways to approach a problem and break it down into parts, how and why to document your code, how to test your code to help ensure your program does what you want it to, and more.
We chose Python for several reasons:
It is free and well documented. In fact, Python is one of the largest and best-organized open source projects going.
It runs everywhere. The reference implementation, written in C, is used on everything from cell phones to supercomputers, and its supported by professional-quality installers for Windows, macOS, and Linux.