forked from bailiangrui/git-basics-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththinkpython2003.html
More file actions
392 lines (364 loc) · 30.9 KB
/
Copy paththinkpython2003.html
File metadata and controls
392 lines (364 loc) · 30.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="generator" content="hevea 2.09">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="thinkpython2.css">
<title>Variables, expressions and statements</title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><strong>Think Python</strong> - How to Think like a Computer Scientist (2e) <em>by Allen B. Downey</em></a>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a href="http://greenteapress.com/thinkpython2/html/index.html"><span class="glyphicon glyphicon glyphicon-book" aria-hidden="true"></span></a></li>
<li><a href="thinkpython2002.html"><span class="glyphicon glyphicon glyphicon-menu-left" aria-hidden="true"></span></a></li>
<li><a href="index.html"><span class="glyphicon glyphicon glyphicon-home" aria-hidden="true"></span></a></li>
<li><a href="thinkpython2004.html"><span class="glyphicon glyphicon glyphicon-menu-right" aria-hidden="true"></span></a></li>
<li><a href="http://amzn.to/1VUYQUU"><span class="glyphicon glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></a></li>
</ul>
<div>
</div><!-- /.container-fluid -->
</nav>
<table>
<tr>
<td valign="top" width="100" bgcolor="#b6459a" id="col-left">
</td>
<td valign="top" id="content">
<p>
<h1 class="chapter" id="sec15">Chapter 2  Variables, expressions and statements</h1>
<p>One of the most powerful features of a programming language is the
ability to manipulate <span class="c010">variables</span>. A variable is a name that
refers to a value.
<a id="hevea_default88"></a></p>
<h2 class="section" id="sec16">2.1  Assignment statements</h2>
<p>
<a id="variables"></a>
<a id="hevea_default89"></a>
<a id="hevea_default90"></a></p><p>An <span class="c010">assignment statement</span> creates a new variable and gives
it a value:</p><pre class="verbatim">>>> message = 'And now for something completely different'
>>> n = 17
>>> pi = 3.141592653589793
</pre><p>This example makes three assignments. The first assigns a string
to a new variable named <span class="c004">message</span>;
the second gives the integer <span class="c004">17</span> to <span class="c004">n</span>; the third
assigns the (approximate) value of π to <span class="c004">pi</span>.
<a id="hevea_default91"></a>
<a id="hevea_default92"></a></p><p>A common way to represent variables on paper is to write the name with
an arrow pointing to its value. This kind of figure is
called a <span class="c010">state diagram</span> because it shows what state each of the
variables is in (think of it as the variable’s state of mind).
Figure <a href="thinkpython2003.html#fig.state2">2.1</a> shows the result of the previous example.</p><blockquote class="figure"><div class="center"><hr class="c019"></div>
<div class="center"><img src="images/thinkpython2001.png"></div>
<div class="caption"><table class="c001 cellpading0"><tr><td class="c018">Figure 2.1: State diagram.</td></tr>
</table></div>
<a id="fig.state2"></a>
<div class="center"><hr class="c019"></div></blockquote>
<h2 class="section" id="sec17">2.2  Variable names</h2>
<p>
<a id="hevea_default93"></a></p><p>Programmers generally choose names for their variables that
are meaningful—they document what the variable is used for.</p><p>Variable names can be as long as you like. They can contain
both letters and numbers, but they can’t begin with a number.
It is legal to use uppercase letters, but it is conventional
to use only lower case for variables names.</p><p>The underscore character, <code>_</code>, can appear in a name.
It is often used in names with multiple words, such as
<code>your_name</code> or <code>airspeed_of_unladen_swallow</code>.
<a id="hevea_default94"></a></p><p>If you give a variable an illegal name, you get a syntax error:</p><pre class="verbatim">>>> 76trombones = 'big parade'
SyntaxError: invalid syntax
>>> more@ = 1000000
SyntaxError: invalid syntax
>>> class = 'Advanced Theoretical Zymurgy'
SyntaxError: invalid syntax
</pre><p><span class="c004">76trombones</span> is illegal because it begins with a number.
<span class="c004">more@</span> is illegal because it contains an illegal character, <span class="c004">@</span>. But what’s wrong with <span class="c004">class</span>?</p><p>It turns out that <span class="c004">class</span> is one of Python’s <span class="c010">keywords</span>. The
interpreter uses keywords to recognize the structure of the program,
and they cannot be used as variable names.
<a id="hevea_default95"></a></p><p>Python 3 has these keywords:</p><pre class="verbatim">False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise
</pre><p>You don’t have to memorize this list. In most development environments,
keywords are displayed in a different color; if you try to use one
as a variable name, you’ll know.</p>
<h2 class="section" id="sec18">2.3  Expressions and statements</h2>
<p>An <span class="c010">expression</span> is a combination of values, variables, and operators.
A value all by itself is considered an expression, and so is
a variable, so the following are all legal expressions:
<a id="hevea_default96"></a></p><pre class="verbatim">>>> 42
42
>>> n
17
>>> n + 25
42
</pre><p>When you type an expression at the prompt, the interpreter
<span class="c010">evaluates</span> it, which means that it finds the value of
the expression.
In this example, <span class="c004">n</span> has the value 17 and
<span class="c004">n + 25</span> has the value 42.
<a id="hevea_default97"></a></p><p>A <span class="c010">statement</span> is a unit of code that has an effect, like
creating a variable or displaying a value.
<a id="hevea_default98"></a></p><pre class="verbatim">>>> n = 17
>>> print(n)
</pre><p>The first line is an assignment statement that gives a value to
<span class="c004">n</span>. The second line is a print statement that displays the
value of <span class="c004">n</span>.</p><p>When you type a statement, the interpreter <span class="c010">executes</span> it,
which means that it does whatever the statement says. In general,
statements don’t have values.
<a id="hevea_default99"></a></p>
<h2 class="section" id="sec19">2.4  Script mode</h2>
<p>So far we have run Python in <span class="c010">interactive mode</span>, which
means that you interact directly with the interpreter.
Interactive mode is a good way to get started,
but if you are working with more than a few lines of code, it can be
clumsy.
<a id="hevea_default100"></a></p><p>The alternative is to save code in a file called a <span class="c010">script</span> and
then run the interpreter in <span class="c010">script mode</span> to execute the script. By
convention, Python scripts have names that end with <span class="c004">.py</span>.
<a id="hevea_default101"></a>
<a id="hevea_default102"></a></p><p>If you know how to create and run a script on your computer, you
are ready to go. Otherwise I recommend using PythonAnywhere again.
I have posted instructions for running in script mode at
<a href="http://tinyurl.com/thinkpython2e"><span class="c004">http://tinyurl.com/thinkpython2e</span></a>.</p><p>Because Python provides both modes,
you can test bits of code in interactive mode before you put them
in a script. But there are differences between interactive mode
and script mode that can be confusing.
<a id="hevea_default103"></a>
<a id="hevea_default104"></a></p><p>For example, if you are using Python as a calculator, you might type</p><pre class="verbatim">>>> miles = 26.2
>>> miles * 1.61
42.182
</pre><p>The first line assigns a value to <span class="c004">miles</span>, but it has no visible
effect. The second line is an expression, so the
interpreter evaluates it and displays the result. It turns out that a
marathon is about 42 kilometers.</p><p>But if you type the same code into a script and run it, you get no
output at all. In script mode an expression, all by itself, has no
visible effect. Python actually evaluates the expression, but it doesn’t
display the value unless you tell it to:</p><pre class="verbatim">miles = 26.2
print(miles * 1.61)
</pre><p>This behavior can be confusing at first.</p><p>A script usually contains a sequence of statements. If there
is more than one statement, the results appear one at a time
as the statements execute.</p><p>For example, the script</p><pre class="verbatim">print(1)
x = 2
print(x)
</pre><p>produces the output</p><pre class="verbatim">1
2
</pre><p>The assignment statement produces no output.</p><p>To check your understanding, type the following statements in the
Python interpreter and see what they do:</p><pre class="verbatim">5
x = 5
x + 1
</pre><p>Now put the same statements in a script and run it. What
is the output? Modify the script by transforming each
expression into a print statement and then run it again.</p>
<h2 class="section" id="sec20">2.5  Order of operations</h2>
<p>
<a id="hevea_default105"></a>
<a id="hevea_default106"></a></p><p>When an expression contains more than one operator, the order of
evaluation depends on the <span class="c010">order of operations</span>. For
mathematical operators, Python follows mathematical convention.
The acronym <span class="c010">PEMDAS</span> is a useful way to
remember the rules:</p><ul class="itemize"><li class="li-itemize"><span class="c010">P</span>arentheses have the highest precedence and can be used
to force an expression to evaluate in the order you want. Since
expressions in parentheses are evaluated first, <span class="c004">2 * (3-1)</span> is 4,
and <span class="c004">(1+1)**(5-2)</span> is 8. You can also use parentheses to make an
expression easier to read, as in <span class="c004">(minute * 100) / 60</span>, even
if it doesn’t change the result.</li><li class="li-itemize"><span class="c010">E</span>xponentiation has the next highest precedence, so
<span class="c004">1 + 2**3</span> is 9, not 27, and <span class="c004">2 * 3**2</span> is 18, not 36.</li><li class="li-itemize"><span class="c010">M</span>ultiplication and <span class="c010">D</span>ivision have higher precedence
than <span class="c010">A</span>ddition and <span class="c010">S</span>ubtraction. So <span class="c004">2*3-1</span> is 5, not
4, and <span class="c004">6+4/2</span> is 8, not 5.</li><li class="li-itemize">Operators with the same precedence are evaluated from left to
right (except exponentiation). So in the expression <span class="c004">degrees /
2 * pi</span>, the division happens first and the result is multiplied
by <span class="c004">pi</span>. To divide by 2 π, you can use parentheses or write
<span class="c004">degrees / 2 / pi</span>.</li></ul><p>I don’t work very hard to remember the precedence of
operators. If I can’t tell by looking at the expression, I use
parentheses to make it obvious.</p>
<h2 class="section" id="sec21">2.6  String operations</h2>
<p>
<a id="hevea_default107"></a>
<a id="hevea_default108"></a></p><p>In general, you can’t perform mathematical operations on strings, even
if the strings look like numbers, so the following are illegal:</p><pre class="verbatim">'2'-'1' 'eggs'/'easy' 'third'*'a charm'
</pre><p>But there are two exceptions, <span class="c004">+</span> and <span class="c004">*</span>.</p><p>The <span class="c004">+</span> operator performs <span class="c010">string concatenation</span>, which means
it joins the strings by linking them end-to-end. For example:
<a id="hevea_default109"></a></p><pre class="verbatim">>>> first = 'throat'
>>> second = 'warbler'
>>> first + second
throatwarbler
</pre><p>The <span class="c004">*</span> operator also works on strings; it performs repetition.
For example, <code>'Spam'*3</code> is <code>'SpamSpamSpam'</code>. If one of the
values is a string, the other has to be an integer.</p><p>This use of <span class="c004">+</span> and <span class="c004">*</span> makes sense by
analogy with addition and multiplication. Just as <span class="c004">4*3</span> is
equivalent to <span class="c004">4+4+4</span>, we expect <code>'Spam'*3</code> to be the same as
<code>'Spam'+'Spam'+'Spam'</code>, and it is. On the other hand, there is a
significant way in which string concatenation and repetition are
different from integer addition and multiplication.
Can you think of a property that addition has
that string concatenation does not?
<a id="hevea_default110"></a></p>
<h2 class="section" id="sec22">2.7  Comments</h2>
<p>
<a id="hevea_default111"></a></p><p>As programs get bigger and more complicated, they get more difficult
to read. Formal languages are dense, and it is often difficult to
look at a piece of code and figure out what it is doing, or why.</p><p>For this reason, it is a good idea to add notes to your programs to explain
in natural language what the program is doing. These notes are called
<span class="c010">comments</span>, and they start with the <code>#</code> symbol:</p><pre class="verbatim"># compute the percentage of the hour that has elapsed
percentage = (minute * 100) / 60
</pre><p>In this case, the comment appears on a line by itself. You can also put
comments at the end of a line:</p><pre class="verbatim">percentage = (minute * 100) / 60 # percentage of an hour
</pre><p>Everything from the <span class="c004">#</span> to the end of the line is ignored—it
has no effect on the execution of the program.</p><p>Comments are most useful when they document non-obvious features of
the code. It is reasonable to assume that the reader can figure out
<em>what</em> the code does; it is more useful to explain <em>why</em>.</p><p>This comment is redundant with the code and useless:</p><pre class="verbatim">v = 5 # assign 5 to v
</pre><p>This comment contains useful information that is not in the code:</p><pre class="verbatim">v = 5 # velocity in meters/second.
</pre><p>Good variable names can reduce the need for comments, but
long names can make complex expressions hard to read, so there is
a tradeoff.</p>
<h2 class="section" id="sec23">2.8  Debugging</h2>
<p>
<a id="hevea_default112"></a>
<a id="hevea_default113"></a></p><p>Three kinds of errors can occur in a program: syntax errors, runtime
errors, and semantic errors. It is useful
to distinguish between them in order to track them down more quickly.</p><dl class="description"><dt class="dt-description"><span class="c010">Syntax error:</span></dt><dd class="dd-description"> “Syntax” refers to the structure of a program
and the rules about that structure. For example, parentheses have
to come in matching pairs, so <span class="c004">(1 + 2)</span> is legal, but <span class="c004">8)</span>
is a <span class="c010">syntax error</span>. <a id="hevea_default114"></a> <a id="hevea_default115"></a>
<a id="hevea_default116"></a>
<a id="hevea_default117"></a> <p>If there is a syntax error
anywhere in your program, Python displays an error message and quits,
and you will not be able to run the program. During the first few
weeks of your programming career, you might spend a lot of
time tracking down syntax errors. As you gain experience, you will
make fewer errors and find them faster.</p></dd><dt class="dt-description"><span class="c010">Runtime error:</span></dt><dd class="dd-description"> The second type of error is a runtime error, so
called because the error does not appear until after the program has
started running. These errors are also called <span class="c010">exceptions</span>
because they usually indicate that something exceptional (and bad)
has happened. <a id="hevea_default118"></a> <a id="hevea_default119"></a>
<a id="hevea_default120"></a> <a id="hevea_default121"></a> <a id="hevea_default122"></a><p>Runtime errors are rare in the simple programs you will see in the
first few chapters, so it might be a while before you encounter one.</p></dd><dt class="dt-description"><span class="c010">Semantic error:</span></dt><dd class="dd-description"> The third type of error is “semantic”, which
means related to meaning. If there is a semantic error in your
program, it will run without generating error messages, but it will
not do the right thing. It will do something else. Specifically,
it will do what you told it to do. <a id="hevea_default123"></a>
<a id="hevea_default124"></a> <a id="hevea_default125"></a><p>Identifying semantic errors can be tricky because it requires you to work
backward by looking at the output of the program and trying to figure
out what it is doing.</p></dd></dl>
<h2 class="section" id="sec24">2.9  Glossary</h2>
<dl class="description"><dt class="dt-description"><span class="c010">variable:</span></dt><dd class="dd-description"> A name that refers to a value.
<a id="hevea_default126"></a></dd><dt class="dt-description"><span class="c010">assignment:</span></dt><dd class="dd-description"> A statement that assigns a value to a variable.
<a id="hevea_default127"></a></dd><dt class="dt-description"><span class="c010">state diagram:</span></dt><dd class="dd-description"> A graphical representation of a set of variables and the
values they refer to.
<a id="hevea_default128"></a></dd><dt class="dt-description"><span class="c010">keyword:</span></dt><dd class="dd-description"> A reserved word that is used to parse a
program; you cannot use keywords like <span class="c004">if</span>, <span class="c004">def</span>, and <span class="c004">while</span> as
variable names.
<a id="hevea_default129"></a></dd><dt class="dt-description"><span class="c010">operand:</span></dt><dd class="dd-description"> One of the values on which an operator operates.
<a id="hevea_default130"></a></dd><dt class="dt-description"><span class="c010">expression:</span></dt><dd class="dd-description"> A combination of variables, operators, and values that
represents a single result.
<a id="hevea_default131"></a></dd><dt class="dt-description"><span class="c010">evaluate:</span></dt><dd class="dd-description"> To simplify an expression by performing the operations
in order to yield a single value.</dd><dt class="dt-description"><span class="c010">statement:</span></dt><dd class="dd-description"> A section of code that represents a command or action. So
far, the statements we have seen are assignments and print statements.
<a id="hevea_default132"></a></dd><dt class="dt-description"><span class="c010">execute:</span></dt><dd class="dd-description"> To run a statement and do what it says.
<a id="hevea_default133"></a></dd><dt class="dt-description"><span class="c010">interactive mode:</span></dt><dd class="dd-description"> A way of using the Python interpreter by
typing code at the prompt.
<a id="hevea_default134"></a></dd><dt class="dt-description"><span class="c010">script mode:</span></dt><dd class="dd-description"> A way of using the Python interpreter to read
code from a script and run it.
<a id="hevea_default135"></a></dd><dt class="dt-description"><span class="c010">script:</span></dt><dd class="dd-description"> A program stored in a file.
<a id="hevea_default136"></a></dd><dt class="dt-description"><span class="c010">order of operations:</span></dt><dd class="dd-description"> Rules governing the order in which
expressions involving multiple operators and operands are evaluated.
<a id="hevea_default137"></a></dd><dt class="dt-description"><span class="c010">concatenate:</span></dt><dd class="dd-description"> To join two operands end-to-end.
<a id="hevea_default138"></a></dd><dt class="dt-description"><span class="c010">comment:</span></dt><dd class="dd-description"> Information in a program that is meant for other
programmers (or anyone reading the source code) and has no effect on the
execution of the program.
<a id="hevea_default139"></a></dd><dt class="dt-description"><span class="c010">syntax error:</span></dt><dd class="dd-description"> An error in a program that makes it impossible
to parse (and therefore impossible to interpret).
<a id="hevea_default140"></a></dd><dt class="dt-description"><span class="c010">exception:</span></dt><dd class="dd-description"> An error that is detected while the program is running.
<a id="hevea_default141"></a></dd><dt class="dt-description"><span class="c010">semantics:</span></dt><dd class="dd-description"> The meaning of a program.
<a id="hevea_default142"></a></dd><dt class="dt-description"><span class="c010">semantic error:</span></dt><dd class="dd-description"> An error in a program that makes it do something
other than what the programmer intended.
<a id="hevea_default143"></a></dd></dl>
<h2 class="section" id="sec25">2.10  Exercises</h2>
<div class="theorem"><span class="c010">Exercise 1</span>  <p><em>Repeating my advice from the previous chapter, whenever you learn
a new feature, you should try it out in interactive mode and make
errors on purpose to see what goes wrong.</em></p><ul class="itemize"><li class="li-itemize"><em>We’ve seen that <span class="c004">n = 42</span> is legal. What about <span class="c004">42 = n</span>?</em></li><li class="li-itemize"><em>How about <span class="c004">x = y = 1</span>?</em></li><li class="li-itemize"><em>In some languages every statement ends with a semi-colon, <span class="c004">;</span>.
What happens if you put a semi-colon at the end of a Python statement?</em></li><li class="li-itemize"><em>What if you put a period at the end of a statement?</em></li><li class="li-itemize"><em>In math notation you can multiply </em><span class="c009">x</span><em> and </em><span class="c009">y</span><em> like this: </em><span class="c009">x y</span><em>.
What happens if you try that in Python?</em></li></ul></div><div class="theorem"><span class="c010">Exercise 2</span>  <p><em>Practice using the Python interpreter as a calculator:
</em><a id="hevea_default144"></a></p><ol class="enumerate" type=1><li class="li-enumerate"><em>The volume of a sphere with radius </em><span class="c009">r</span><em> is </em>4/3 π <span class="c009">r</span><sup>3</sup><em>.
What is the volume of a sphere with radius 5?</em></li><li class="li-enumerate"><em>Suppose the cover price of a book is $24.95, but bookstores get a
40% discount. Shipping costs $3 for the first copy and 75 cents
for each additional copy. What is the total wholesale cost for
60 copies?</em></li><li class="li-enumerate"><em>If I leave my house at 6:52 am and run 1 mile at an easy pace
(8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at
easy pace again, what time do I get home for breakfast?
</em><a id="hevea_default145"></a></li></ol></div>
<p>
</td>
<td width=130 valign="top" id="col-right">
<p>
<h4>Are you using one of our books in a class?</h4> We'd like to know
about it. Please consider filling out <a href="http://spreadsheets.google.com/viewform?formkey=dC0tNUZkMjBEdXVoRGljNm9FRmlTMHc6MA" onClick="javascript: pageTracker._trackPageview('/outbound/survey');">this short survey</a>.
<p>
<br>
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491938455/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491938455&linkCode=as2&tag=greenteapre01-20&linkId=2JJH4SWCAVVYSQHO">Think DSP</a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491938455" width="1" height="1" border="0" alt="">
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491938455/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491938455&linkCode=as2&tag=greenteapre01-20&linkId=CTV7PDT7E5EGGJUM"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1491938455&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491938455" width="1" height="1" border="0" alt="">
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491929561/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491929561&linkCode=as2&tag=greenteapre01-20&linkId=ZY6MAYM33ZTNSCNZ">Think Java</a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491929561" width="1" height="1" border="0" alt="">
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491929561/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491929561&linkCode=as2&tag=greenteapre01-20&linkId=PT77ANWARUNNU3UK"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1491929561&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491929561" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1449370780/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1449370780&linkCode=as2&tag=greenteapre01-20">Think Bayes</a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1449370780" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1449370780/ref=as_li_qf_sp_asin_il?ie=UTF8&camp=1789&creative=9325&creativeASIN=1449370780&linkCode=as2&tag=greenteapre01-20"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1449370780&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1449370780" width="1" height="1" border="0" alt="">
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491939362/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491939362&linkCode=as2&tag=greenteapre01-20&linkId=FJKSQ3IHEMY2F2VA">Think Python 2e</a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491939362" width="1" height="1" border="0" alt="">
<p>
<a rel="nofollow" href="http://www.amazon.com/gp/product/1491939362/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491939362&linkCode=as2&tag=greenteapre01-20&linkId=ZZ454DLQ3IXDHNHX"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1491939362&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491939362" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1491907339/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491907339&linkCode=as2&tag=greenteapre01-20&linkId=O7WYM6H6YBYUFNWU">Think Stats 2e</a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491907339" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1491907339/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1491907339&linkCode=as2&tag=greenteapre01-20&linkId=JVSYKQHYSUIEYRHL"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1491907339&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://ir-na.amazon-adsystem.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1491907339" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1449314635/ref=as_li_tf_tl?ie=UTF8&tag=greenteapre01-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1449314635">Think Complexity</a><img class="c003" src="http://www.assoc-amazon.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1449314635" width="1" height="1" border="0" alt="">
<p>
<a href="http://www.amazon.com/gp/product/1449314635/ref=as_li_tf_il?ie=UTF8&camp=1789&creative=9325&creativeASIN=1449314635&linkCode=as2&tag=greenteapre01-20"><img border="0" src="http://ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=1449314635&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=greenteapre01-20"></a><img class="c003" src="http://www.assoc-amazon.com/e/ir?t=greenteapre01-20&l=as2&o=1&a=1449314635" width="1" height="1" border="0" alt="">
</td>
</tr>
</table>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><strong>Think Python</strong> - How to Think like a Computer Scientist (2e) <em>by Allen B. Downey</em></a>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a href="http://greenteapress.com/thinkpython2/html/index.html"><span class="glyphicon glyphicon glyphicon-book" aria-hidden="true"></span></a></li>
<li><a href="thinkpython2002.html"><span class="glyphicon glyphicon glyphicon-menu-left" aria-hidden="true"></span></a></li>
<li><a href="index.html"><span class="glyphicon glyphicon glyphicon-home" aria-hidden="true"></span></a></li>
<li><a href="thinkpython2004.html"><span class="glyphicon glyphicon glyphicon-menu-right" aria-hidden="true"></span></a></li>
<li><a href="http://amzn.to/1VUYQUU"><span class="glyphicon glyphicon glyphicon-shopping-cart" aria-hidden="true"></span></a></li>
</ul>
<div>
</div><!-- /.container-fluid -->
</nav></body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</html>