Buy ebook Think Python 1st Edition Allen B Downey cheap price
Buy ebook Think Python 1st Edition Allen B Downey cheap price
com
https://ebookmeta.com/product/think-python-1st-edition-
allen-b-downey/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/think-python-2nd-edition-allen-b-downey/
ebookmeta.com
https://ebookmeta.com/product/think-python-how-to-think-like-a-
computer-scientist-allen-b-downey/
ebookmeta.com
https://ebookmeta.com/product/think-python-how-to-think-like-a-
computer-scientist-2nd-edition-allen-b-downey/
ebookmeta.com
https://ebookmeta.com/product/potato-kitchen-from-soil-to-table-more-
than-70-inspiring-recipes-1st-edition-manuela-ruther/
ebookmeta.com
Understanding Semiconductors 1st Edition Corey Richard
https://ebookmeta.com/product/understanding-semiconductors-1st-
edition-corey-richard/
ebookmeta.com
https://ebookmeta.com/product/diabetes-meal-planning-nutrition-for-
dummies-2nd-edition-simon-poole/
ebookmeta.com
https://ebookmeta.com/product/exhale-fresh-hell-book-2-1st-edition-
charity-parkerson/
ebookmeta.com
Conceiving Desire in Lyly and Shakespeare Metaphor
Cognition and Eros Edinburgh Critical Studies in
Shakespeare and Philosophy 1st Edition Gillian Knoll
https://ebookmeta.com/product/conceiving-desire-in-lyly-and-
shakespeare-metaphor-cognition-and-eros-edinburgh-critical-studies-in-
shakespeare-and-philosophy-1st-edition-gillian-knoll/
ebookmeta.com
Think Python
Allen B. Downey
Think Python
by Allen B. Downey
Copyright © 2012 Allen Downey. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or [email protected].
Editors: Mike Loukides and Meghan Blanchette Proofreader: Stacie Arellano
Production Editor: Rachel Steely Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrators: Robert Romano and Rebecca Demarest
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc. Think Python, the image of a Carolina Parrot, and related trade dress are trademarks of O’Reilly
Media, Inc.
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 O’Reilly Media, Inc., was aware of a trade
mark claim, the designations have been printed in caps or initial caps.
Think Python is available under the Creative Commons Attribution-NonCommercial 3.0 Unported License.
The author maintains an online version at http://thinkpython.com/thinkpython.pdf.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-33072-9
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
iii
Exercises 21
3. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Function Calls 23
Type Conversion Functions 23
Math Functions 24
Composition 25
Adding New Functions 25
Definitions and Uses 27
Flow of Execution 27
Parameters and Arguments 28
Variables and Parameters Are Local 29
Stack Diagrams 30
Fruitful Functions and Void Functions 31
Why Functions? 32
Importing with from 32
Debugging 33
Glossary 33
Exercises 35
iv | Table of Contents
Recursion 53
Stack Diagrams for Recursive Functions 54
Infinite Recursion 55
Keyboard Input 55
Debugging 56
Glossary 57
Exercises 58
6. Fruitful Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Return Values 61
Incremental Development 62
Composition 64
Boolean Functions 65
More Recursion 66
Leap of Faith 68
One More Example 68
Checking Types 69
Debugging 70
Glossary 71
Exercises 72
7. Iteration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Multiple Assignment 75
Updating Variables 76
The while Statement 76
break 78
Square Roots 79
Algorithms 80
Debugging 81
Glossary 81
Exercises 82
8. Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
A String Is a Sequence 85
len 86
Traversal with a for Loop 86
String Slices 87
Strings Are Immutable 88
Searching 89
Looping and Counting 89
String Methods 90
The in Operator 91
Table of Contents | v
String Comparison 92
Debugging 92
Glossary 94
Exercises 95
vi | Table of Contents
Exercises 133
A. Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
C. Lumpy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Table of Contents | ix
Preface
xi
My first version was rough, but it worked. Students did the reading, and they understood
enough that I could spend class time on the hard topics, the interesting topics and (most
important) letting the students practice.
I released the book under the GNU Free Documentation License, which allows users
to copy, modify, and distribute the book.
What happened next is the cool part. Jeff Elkner, a high school teacher in Virginia,
adopted my book and translated it into Python. He sent me a copy of his translation,
and I had the unusual experience of learning Python by reading my own book. As Green
Tea Press, I published the first Python version in 2001.
In 2003 I started teaching at Olin College and I got to teach Python for the first time.
The contrast with Java was striking. Students struggled less, learned more, worked on
more interesting projects, and generally had a lot more fun.
Over the last nine years I continued to develop the book, correcting errors, improving
some of the examples and adding material, especially exercises.
The result is this book, now with the less grandiose title Think Python. Some of the
changes are:
• I added a section about debugging at the end of each chapter. These sections present
general techniques for finding and avoiding bugs, and warnings about Python
pitfalls.
• I added more exercises, ranging from short tests of understanding to a few sub
stantial projects. And I wrote solutions for most of them.
• I added a series of case studies—longer examples with exercises, solutions, and
discussion. Some are based on Swampy, a suite of Python programs I wrote for use
in my classes. Swampy, code examples, and some solutions are available from http://
thinkpython.com.
• I expanded the discussion of program development plans and basic design patterns.
• I added appendices about debugging, analysis of algorithms, and UML diagrams
with Lumpy.
I hope you enjoy working with this book, and that it helps you learn to program and
think, at least a little bit, like a computer scientist.
—Allen B. Downey
Needham, MA
xii | Preface
Acknowledgments
Many thanks to Jeff Elkner, who translated my Java book into Python, which got this
project started and introduced me to what has turned out to be my favorite language.
Thanks also to Chris Meyers, who contributed several sections to How to Think Like a
Computer Scientist.
Thanks to the Free Software Foundation for developing the GNU Free Documentation
License, which helped make my collaboration with Jeff and Chris possible, and Creative
Commons for the license I am using now.
Thanks to the editors at Lulu who worked on How to Think Like a Computer Scientist.
Thanks to all the students who worked with earlier versions of this book and all the
contributors (listed below) who sent in corrections and suggestions.
Contributor List
More than 100 sharp-eyed and thoughtful readers have sent in suggestions and correc
tions over the past few years. Their contributions, and enthusiasm for this project, have
been a huge help. If you have a suggestion or correction, please send email to feed
[email protected]. If I make a change based on your feedback, I will add you to
the contributor list (unless you ask to be omitted).
If you include at least part of the sentence the error appears in, that makes it easy for
me to search. Page and section numbers are fine, too, but not quite as easy to work with.
Thanks!
• Lloyd Hugh Allen sent in a correction to Section 8.4.
• Yvon Boulianne sent in a correction of a semantic error in Chapter 5.
• Fred Bremmer submitted a correction in Section 2.1.
• Jonah Cohen wrote the Perl scripts to convert the LaTeX source for this book into beautiful HTML.
• Michael Conlon sent in a grammar correction in Chapter 2 and an improvement in style in Chapter
1, and he initiated discussion on the technical aspects of interpreters.
• Benoit Girard sent in a correction to a humorous mistake in Section 5.6.
• Courtney Gleason and Katherine Smith wrote horsebet.py, which was used as a case study in an
earlier version of the book. Their program can now be found on the website.
• Lee Harr submitted more corrections than we have room to list here, and indeed he should be listed
as one of the principal editors of the text.
• James Kaylin is a student using the text. He has submitted numerous corrections.
Preface | xiii
Other documents randomly have
different content
from the complicated compounds found in the soil, or take it from the
air only by aid of certain Bacteria.
Certain plants manufacture lime and metallic oxides with which to
harden the protective armour they wear. Many others generate nitric
acid, carbonic acid and ammonia for use in their interior laboratories.
Roots nearly always secrete a fluid which aids in the absorption of
minerals from the earth. It is so powerful that quartz, flint and
limestone are often scratched and corroded by its action. Above and
below ground, plants are active chemical laboratories.
The differences of taste, smell and colour which characterize
leaves, blossoms and fruits are due to the presence of various
organic compounds. These are largely volatile oils which are more
complex than the substances involved in the simpler life processes.
The slow or rapid evaporation of these oils influences the strength
and character of an odour. When a flower or fruit passes through
infinite gradations of colour, we can give no adequate account of the
chemical changes involved. All we can do is to observe and to note.
Sometimes infusions of iron sulphate or other chemicals in the soil
darken the hues of flowers. Gardeners profit by this fact in the
cultivation of certain varieties of Hortensia.
The chemical activities of plants are of incalculable value to man.
They change air, water and mineral salts into forms easily
assimilable by the human system. Eliminate all the vegetable life
from this planet, and the animals, including man, would perish in a
few months. Man has also learned to make abundant use of plant
substances for innumerable purposes. Potash is an example of how
the plants come to our aid in furnishing us a valuable chemical. It is
extracted from wood, Seaweed and Banana stalks. These plants
have discovered a way of getting it out of its well-nigh insoluble earth
combinations with silica. If it had not been for certain industrious sea
plants, man would probably never have been aware of the important
chemical twins, bromine and iodine, so important in photography.
These plants patiently filter them out of sea water where they exist in
microscopic quantities, and build them into their bodies. Beer is
possible because germinating grains transform amylum or plant
starch into sugar. We find ripe fruits palatable because their acids
change into sugar under the influence of sunlight.
Man seems to have outstripped the plants in the use of light, heat,
electricity, and other physical forces, but the plants have more
engineers among them than we imagine. In the fact that man has
just learned to extract nitrogen from the air by the agency of
electrical discharges, lies the probable explanation of how the plants
have been doing the same thing for years. It is believed that the
minute electrical discharges continually going on between the
different air strata make small quantities of nitrogen assimilable for
the plants. The micro-organisms which also furnish nitrogenous
material to the plants may get nitrogen from the air in the same way.
It is quite certain that the plants are affected by the chemical state of
the atmosphere.
Everyone knows what an important part light plays in plant
physiology, but the fact that certain plants produce their own lights,
while generally known, is not universally understood. The Austrian
naturalist, Heller, was the first to demonstrate that the glowing of
decayed wood at night is caused by emanations of light from Fungus
growing in the cavities. A similiar organism called Luminous
Peridineas (sometimes classed as an animal) is responsible for the
phosphorescence of the ocean and the night lights of many flowers.
About three hundred species of Bacteria and fifteen species of
Fungus are recognized to be luminous. The dead leaves of the
tropical Banibusa, Nephelium and Aglaia often glow at night with the
light of these tiny creatures. Ordinary dead Oak and Beech leaves
are luminous, sometimes shining in spots, but frequently glowing
throughout with a soft, white, steady light. These miniature
incandescent lights often shine for days, weeks and months, and
with abundant nutriment at hand, sometimes for years. The light is
slight in intensity, but uniformly steady and white, green or blue-
green in colour. It is strong enough to enable the plants on which the
Fungus grows to photograph themselves by long exposure to
sensitized plates. The fungus light has also been used to influence
the heliotropic movements of plant seedlings. In fact, a colony of
Fungus has sometimes been placed in an electric light bulb and
made thus to serve as an illuminant.
No matter from what angle we study the plants, we find that they
are extremely scientific. They conduct themselves and all their
activities in a way to always get the best results. They show
knowledge and acquaintance with all of Nature’s laws, and they have
learned to apply many of them with startling success.
MODERN NATURE WORSHIPPERS
CHAPTER X
Religion in the Plant World