DOC PREVIEW
MSU AST 308 - think_Python_Programmer

This preview shows page 1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-111-112-113-114-115-116-117-118-119-120-121-122-123-124-125-126-224-225-226-227-228-229-230-231-232-233-234-235-236-237-238-239 out of 239 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 239 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

How to Think Like a(Python) ProgrammerVersion 0.9.10iiHow to Think Like a(Python) ProgrammerVersion 0.9.10Allen DowneyGreen Tea PressNeedham, MassachusettsCopyrightc 2007 Allen Downey.Printing history:April 2002: First edition of How to Think Like a Computer Scientist.August 2007: Major revision, changed title to How to Think Like a (Python) Pro-grammer.Green Tea Press9 Washburn AveNeedham MA 02492Permission is granted to copy, distribute, and/or mod ify this document under the termsof the GNU Free Documentation License, Version 1.1 or any later version publishedby the Free Software Foundation; with no Invariant Sections, no Fr ont-Cover Texts,and with no Back-Cover Texts.The GNU Free Documentation License is available from www.gnu.org or by writing tothe Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.The original form of this book is LATEX source code. Compiling this LATEX source hasthe effect of generating a device-independent representation of a textbook, which canb e converted to other formats and printed.The LATEX source f or this book is available from http://www.thinkpython.comPrefaceThe strange history of this bookIn January 1999 I was preparing to teach an introductory programming class inJava. I had taught it three times and I was getting frustrated. The failure ratein the class was too high and even for students who succeeded, the overall levelof achievement was too low.One of the problems I saw was the books. I had tried three different books(and read a dozen more), and they all had the same problems. They were toobig, with too much unnecessary detail about Java, and not enough high-levelguidance about how to program. And they all suffered from the trap dooreffect: they would start out very gradual and easy, and then somewhere aroundChapter 5, the bottom would fall out. The students would get too much newmaterial, too fast, and I would spend the rest of the semester picking up thepieces.Two weeks before the first day of classes, I decided to write my own book. Iwrote one 10-page chapter a day for 13 days. I made some revisions on Day 14and then sent it out to be photocopied.My goals were:• Keep it short. It is better for students to read 10 pages than not read 50pages.• Be careful with vocabulary. I tried to minimize the jargon and define eachterm at first use.• Build gradually. To avoid trap doors, I took the most difficult topics andsplit them into a series of small steps.• It’s not about the language; it’s about programming. I included the minu-mum useful subset of Java and left out the rest.I needed a title, so on a whim I chose How to Think Like a Computer Scientist.vi Chapter 0. PrefaceMy first version was rough, but it worked. Students did the reading, and theyunderstood enough that I could spend class time on the hard topics, the inter-esting topics and (most important) letting the students practice.As a user and advocate of free software, I believe in the idea Benjamin Franklinexpressed:“As we enjoy great Advantages from the Inventions of others, weshould be glad of an Opportunity to serve others by any Inventionof ours, and this we should do freely and generously.”So I released the book under the GNU Free Documenation License, which allowsusers to copy, modify, and distribute the book.What happened next is the cool part. Jeff Elkner, a high school teacher inVirginia, adopted my book and translated it into Python. He sent me a copy ofhis translation, and I had the unusual experience of learning Python by readingmy own book.Jeff and I revised the book, incorporated a case study by Chris Meyers, andreleased How to Think Like a Computer Scientist: Learning with Python, alsounder the GNU Free Documenation License.At the same time, my wife and I started Green Tea Press, which distributesseveral of my books electronically, and sells How to Think in hard copy.I have been teaching with this book for more than five years now, and I havedone a lot more Python programming. I still like the structure of the book, butfor some time I have felt the need to make changes:• Some of the examples in the first edition work better than others. Inmy classes I have discarded the less effective ones and developed improve-ments.• There are only a few exercises in the first edition. Now I have five yearsof quizzes, exams and homeworks to choose from.• I have been programming in Python for a while now and have a better ap-preciation of idiomatic Python. The book is still about programming, notPython, but now I think the book gets more leverage from the language.At the same time, Jeff has been working on his own second edition, customizedfor his classes. Rather than cram everything into one book (which may behow other books got so big), we decided to work on different versions. They areboth under the Free Documentation License, so users can choose one or combinematerial from both.For my version, I am using the revised title How to Think Like a (Python)Programmer. This is a more modest goal than the original, but it might bemore accurate.viiAllen B. DowneyNeedham MAAllen Downey is a Professor of Computer Science at the Franklin W. Olin Col-lege of Engineering.For the teacherSwampy and UMLFor the studentTry out examples.Do the in-chapter examples.Where to get the code.Contributor ListTo paraphrase the philosophy of the Free Software Foundation, this book isfree like free speech, but not necessarily free like free pizza. It came aboutbecause of a collaboration that would not have been possible without the GNUFree Documentation License. So we thank the Free Software Foundation fordeveloping this license and, of course, making it available to us.We also thank the more than 100 sharp-eyed and thoughtful readers who havesent us suggestions and corrections over the past few years. In the spirit of freesoftware, we decided to express our gratitude in the form of a contributor list.Unfortunately, this list is not complete, but we are doing our best to keep it upto date.If you have a chance to look through the list, you should realize that each personhere has spared you and all subsequent readers from the confusion of a technicalerror or a less-than-transparent explanation, just by sending us a note.Impossible as it may seem after so many corrections, there may still be errorsin this book. If you should stumble across one, please check the online versionof the book at http://thinkpython.com, which is the most up-to-date ver sion.If


View Full Document

MSU AST 308 - think_Python_Programmer

Download think_Python_Programmer
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view think_Python_Programmer and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view think_Python_Programmer 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?