-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-the-way.html
497 lines (479 loc) · 27.6 KB
/
01-the-way.html
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The way of the program — Pense Python 2e documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2e',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Pense Python 2e documentation" href="index.html" />
<link rel="next" title="Variables, expressions and statements" href="02-statement.html" />
<link rel="prev" title="Preface" href="00-front-matter.html" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="the-way-of-the-program">
<h1>The way of the program<a class="headerlink" href="#the-way-of-the-program" title="Permalink to this headline">¶</a></h1>
<p>The goal of this book is to teach you to think like a computer
scientist. This way of thinking combines some of the best features of
mathematics, engineering, and natural science. Like mathematicians,
computer scientists use formal languages to denote ideas (specifically
computations). Like engineers, they design things, assembling components
into systems and evaluating tradeoffs among alternatives. Like
scientists, they observe the behavior of complex systems, form
hypotheses, and test predictions.</p>
<p>The single most important skill for a computer scientist is <strong>problem
solving</strong>. Problem solving means the ability to formulate problems,
think creatively about solutions, and express a solution clearly and
accurately. As it turns out, the process of learning to program is an
excellent opportunity to practice problem-solving skills. That’s why
this chapter is called, “The way of the program”.</p>
<p>On one level, you will be learning to program, a useful skill by itself.
On another level, you will use programming as a means to an end. As we
go along, that end will become clearer.</p>
<div class="section" id="what-is-a-program">
<h2>What is a program?<a class="headerlink" href="#what-is-a-program" title="Permalink to this headline">¶</a></h2>
<p>A <strong>program</strong> is a sequence of instructions that specifies how to
perform a computation. The computation might be something mathematical,
such as solving a system of equations or finding the roots of a
polynomial, but it can also be a symbolic computation, such as searching
and replacing text in a document or something graphical, like processing
an image or playing a video.</p>
<p>The details look different in different languages, but a few basic
instructions appear in just about every language:</p>
<dl class="docutils">
<dt>input:</dt>
<dd>Get data from the keyboard, a file, the network, or some other
device.</dd>
<dt>output:</dt>
<dd>Display data on the screen, save it in a file, send it over the
network, etc.</dd>
<dt>math:</dt>
<dd>Perform basic mathematical operations like addition and
multiplication.</dd>
<dt>conditional execution:</dt>
<dd>Check for certain conditions and run the appropriate code.</dd>
<dt>repetition:</dt>
<dd>Perform some action repeatedly, usually with some variation.</dd>
</dl>
<p>Believe it or not, that’s pretty much all there is to it. Every program
you’ve ever used, no matter how complicated, is made up of instructions
that look pretty much like these. So you can think of programming as the
process of breaking a large, complex task into smaller and smaller
subtasks until the subtasks are simple enough to be performed with one
of these basic instructions.</p>
</div>
<div class="section" id="running-python">
<h2>Running Python<a class="headerlink" href="#running-python" title="Permalink to this headline">¶</a></h2>
<p>One of the challenges of getting started with Python is that you might
have to install Python and related software on your computer. If you are
familiar with your operating system, and especially if you are
comfortable with the command-line interface, you will have no trouble
installing Python. But for beginners, it can be painful to learn about
system administration and programming at the same time.</p>
<p>To avoid that problem, I recommend that you start out running Python in
a browser. Later, when you are comfortable with Python, I’ll make
suggestions for installing Python on your computer.</p>
<p>There are a number of web pages you can use to run Python. If you
already have a favorite, go ahead and use it. Otherwise I recommend
PythonAnywhere. I provide detailed instructions for getting started at
<a class="reference external" href="http://tinyurl.com/thinkpython2e">http://tinyurl.com/thinkpython2e</a>.</p>
<p>There are two versions of Python, called Python 2 and Python 3. They are
very similar, so if you learn one, it is easy to switch to the other. In
fact, there are only a few differences you will encounter as a beginner.
This book is written for Python 3, but I include some notes about Python
2.</p>
<p>The Python <strong>interpreter</strong> is a program that reads and executes Python
code. Depending on your environment, you might start the interpreter by
clicking on an icon, or by typing python on a command line. When it
starts, you should see output like this:</p>
<div class="highlight-python"><div class="highlight"><pre>Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre></div>
</div>
<p>The first three lines contain information about the interpreter and the
operating system it’s running on, so it might be different for you. But
you should check that the version number, which is 3.4.0 in this
example, begins with 3, which indicates that you are running Python 3.
If it begins with 2, you are running (you guessed it) Python 2.</p>
<p>The last line is a <strong>prompt</strong> that indicates that the interpreter is
ready for you to enter code. If you type a line of code and hit Enter,
the interpreter displays the result:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Now you’re ready to get started. From here on, I assume that you know
how to start the Python interpreter and run code.</p>
</div>
<div class="section" id="the-first-program">
<h2>The first program<a class="headerlink" href="#the-first-program" title="Permalink to this headline">¶</a></h2>
<p>Traditionally, the first program you write in a new language is called
“Hello, World!” because all it does is display the words “Hello,
World!”. In Python, it looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="s">'Hello, World!'</span><span class="p">)</span>
</pre></div>
</div>
<p>This is an example of a <strong>print statement</strong>, although it doesn’t
actually print anything on paper. It displays a result on the screen. In
this case, the result is the words</p>
<div class="highlight-python"><div class="highlight"><pre>Hello, World!
</pre></div>
</div>
<p>The quotation marks in the program mark the beginning and end of the
text to be displayed; they don’t appear in the result.</p>
<p>The parentheses indicate that print is a function. We’ll get to
functions in Chapter [funcchap].</p>
<p>In Python 2, the print statement is slightly different; it is not a
function, so it doesn’t use parentheses.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="s">'Hello, World!'</span>
</pre></div>
</div>
<p>This distinction will make more sense soon, but that’s enough to get
started.</p>
</div>
<div class="section" id="arithmetic-operators">
<h2>Arithmetic operators<a class="headerlink" href="#arithmetic-operators" title="Permalink to this headline">¶</a></h2>
<p>After “Hello, World”, the next step is arithmetic. Python provides
<strong>operators</strong>, which are special symbols that represent computations
like addition and multiplication.</p>
<p>The operators +, -, and perform addition, subtraction, and
multiplication, as in the following examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">40</span> <span class="o">+</span> <span class="mi">2</span>
<span class="go">42</span>
<span class="gp">>>> </span><span class="mi">43</span> <span class="o">-</span> <span class="mi">1</span>
<span class="go">42</span>
<span class="gp">>>> </span><span class="mi">6</span> <span class="o">*</span> <span class="mi">7</span>
<span class="go">42</span>
</pre></div>
</div>
<p>The operator / performs division:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">84</span> <span class="o">/</span> <span class="mi">2</span>
<span class="go">42.0</span>
</pre></div>
</div>
<p>You might wonder why the result is 42.0 instead of 42. I’ll explain in
the next section.</p>
<p>Finally, the operator * performs exponentiation; that is, it raises a
number to a power:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">6</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">6</span>
<span class="go">42</span>
</pre></div>
</div>
<p>In some other languages, <code class="docutils literal"><span class="pre">^</span></code> is used for exponentiation, but in Python
it is a bitwise operator called XOR. If you are not familiar with
bitwise operators, the result will surprise you:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">6</span> <span class="o">^</span> <span class="mi">2</span>
<span class="go">4</span>
</pre></div>
</div>
<p>I won’t cover bitwise operators in this book, but you can read about
them at <a class="reference external" href="http://wiki.python.org/moin/BitwiseOperators">http://wiki.python.org/moin/BitwiseOperators</a>.</p>
</div>
<div class="section" id="values-and-types">
<h2>Values and types<a class="headerlink" href="#values-and-types" title="Permalink to this headline">¶</a></h2>
<p>A <strong>value</strong> is one of the basic things a program works with, like a
letter or a number. Some values we have seen so far are 2, 42.0, and
<code class="docutils literal"><span class="pre">'Hello,</span> <span class="pre">World!'</span></code>.</p>
<p>These values belong to different <strong>types</strong>: 2 is an <strong>integer</strong>, 42.0 is
a <strong>floating-point number</strong>, and <code class="docutils literal"><span class="pre">'Hello,</span> <span class="pre">World!'</span></code> is a <strong>string</strong>,
so-called because the letters it contains are strung together.</p>
<p>If you are not sure what type a value has, the interpreter can tell you:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go"><class 'int'></span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="mf">42.0</span><span class="p">)</span>
<span class="go"><class 'float'></span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="s">'Hello, World!'</span><span class="p">)</span>
<span class="go"><class 'str'></span>
</pre></div>
</div>
<p>In these results, the word “class” is used in the sense of a category; a
type is a category of values.</p>
<p>Not surprisingly, integers belong to the type int, strings belong to str
and floating-point numbers belong to float.</p>
<p>What about values like <code class="docutils literal"><span class="pre">'2'</span></code> and <code class="docutils literal"><span class="pre">'42.0'</span></code>? They look like numbers,
but they are in quotation marks like strings.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="s">'2'</span><span class="p">)</span>
<span class="go"><class 'str'></span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="s">'42.0'</span><span class="p">)</span>
<span class="go"><class 'str'></span>
</pre></div>
</div>
<p>They’re strings.</p>
<p>When you type a large integer, you might be tempted to use commas
between groups of digits, as in 1,000,000. This is not a legal <em>integer</em>
in Python, but it is legal:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="mi">1</span><span class="p">,</span><span class="mo">000</span><span class="p">,</span><span class="mo">000</span>
<span class="go">(1, 0, 0)</span>
</pre></div>
</div>
<p>That’s not what we expected at all! Python interprets 1,000,000 as a
comma-separated sequence of integers. We’ll learn more about this kind
of sequence later.</p>
</div>
<div class="section" id="formal-and-natural-languages">
<h2>Formal and natural languages<a class="headerlink" href="#formal-and-natural-languages" title="Permalink to this headline">¶</a></h2>
<p><strong>Natural languages</strong> are the languages people speak, such as English,
Spanish, and French. They were not designed by people (although people
try to impose some order on them); they evolved naturally.</p>
<p><strong>Formal languages</strong> are languages that are designed by people for
specific applications. For example, the notation that mathematicians use
is a formal language that is particularly good at denoting relationships
among numbers and symbols. Chemists use a formal language to represent
the chemical structure of molecules. And most importantly:</p>
<blockquote>
<div><strong>Programming languages are formal languages that have been designed
to express computations.</strong></div></blockquote>
<p>Formal languages tend to have strict <strong>syntax</strong> rules that govern the
structure of statements. For example, in mathematics the statement
<span class="math">3 + 3 = 6</span> has correct syntax, but <span class="math">3 + = 3 \$ 6</span> does not.
In chemistry <span class="math">H_2O</span> is a syntactically correct formula, but
<span class="math">_2Zz</span> is not.</p>
<p>Syntax rules come in two flavors, pertaining to <strong>tokens</strong> and
structure. Tokens are the basic elements of the language, such as words,
numbers, and chemical elements. One of the problems with
<span class="math">3 += 3 \$ 6</span> is that :math:` $ ` is not a legal token in
mathematics (at least as far as I know). Similarly, <span class="math">_2Zz</span> is not
legal because there is no element with the abbreviation <span class="math">Zz</span>.</p>
<p>The second type of syntax rule pertains to the way tokens are combined.
The equation <span class="math">3 += 3</span> is illegal because even though <span class="math">+</span> and
<span class="math">=</span> are legal tokens, you can’t have one right after the other.
Similarly, in a chemical formula the subscript comes after the element
name, not before.</p>
<p>This is @ well-structured Engli$h sentence with invalid t*kens in it.
This sentence all valid tokens has, but invalid structure with.</p>
<p>When you read a sentence in English or a statement in a formal language,
you have to figure out the structure (although in a natural language you
do this subconsciously). This process is called <strong>parsing</strong>.</p>
<p>Although formal and natural languages have many features in
common—tokens, structure, and syntax—there are some differences:</p>
<dl class="docutils">
<dt>ambiguity:</dt>
<dd>Natural languages are full of ambiguity, which people deal with by
using contextual clues and other information. Formal languages are
designed to be nearly or completely unambiguous, which means that
any statement has exactly one meaning, regardless of context.</dd>
<dt>redundancy:</dt>
<dd>In order to make up for ambiguity and reduce misunderstandings,
natural languages employ lots of redundancy. As a result, they are
often verbose. Formal languages are less redundant and more concise.</dd>
<dt>literalness:</dt>
<dd>Natural languages are full of idiom and metaphor. If I say, “The
penny dropped”, there is probably no penny and nothing dropping
(this idiom means that someone understood something after a period
of confusion). Formal languages mean exactly what they say.</dd>
</dl>
<p>Because we all grow up speaking natural languages, it is sometimes hard
to adjust to formal languages. The difference between formal and natural
language is like the difference between poetry and prose, but more so:</p>
<dl class="docutils">
<dt>Poetry:</dt>
<dd>Words are used for their sounds as well as for their meaning, and
the whole poem together creates an effect or emotional response.
Ambiguity is not only common but often deliberate.</dd>
<dt>Prose:</dt>
<dd>The literal meaning of words is more important, and the structure
contributes more meaning. Prose is more amenable to analysis than
poetry but still often ambiguous.</dd>
<dt>Programs:</dt>
<dd>The meaning of a computer program is unambiguous and literal, and
can be understood entirely by analysis of the tokens and structure.</dd>
</dl>
<p>Formal languages are more dense than natural languages, so it takes
longer to read them. Also, the structure is important, so it is not
always best to read from top to bottom, left to right. Instead, learn to
parse the program in your head, identifying the tokens and interpreting
the structure. Finally, the details matter. Small errors in spelling and
punctuation, which you can get away with in natural languages, can make
a big difference in a formal language.</p>
</div>
<div class="section" id="debugging">
<h2>Debugging<a class="headerlink" href="#debugging" title="Permalink to this headline">¶</a></h2>
<p>Programmers make mistakes. For whimsical reasons, programming errors are
called <strong>bugs</strong> and the process of tracking them down is called
<strong>debugging</strong>.</p>
<p>Programming, and especially debugging, sometimes brings out strong
emotions. If you are struggling with a difficult bug, you might feel
angry, despondent, or embarrassed.</p>
<p>There is evidence that people naturally respond to computers as if they
were people. When they work well, we think of them as teammates, and
when they are obstinate or rude, we respond to them the same way we
respond to rude, obstinate people (Reeves and Nass, <em>The Media Equation:
How People Treat Computers, Television, and New Media Like Real People
and Places</em>).</p>
<p>Preparing for these reactions might help you deal with them. One
approach is to think of the computer as an employee with certain
strengths, like speed and precision, and particular weaknesses, like
lack of empathy and inability to grasp the big picture.</p>
<p>Your job is to be a good manager: find ways to take advantage of the
strengths and mitigate the weaknesses. And find ways to use your
emotions to engage with the problem, without letting your reactions
interfere with your ability to work effectively.</p>
<p>Learning to debug can be frustrating, but it is a valuable skill that is
useful for many activities beyond programming. At the end of each
chapter there is a section, like this one, with my suggestions for
debugging. I hope they help!</p>
</div>
<div class="section" id="glossary">
<span id="glossary01"></span><h2>Glossary<a class="headerlink" href="#glossary" title="Permalink to this headline">¶</a></h2>
<dl class="docutils">
<dt>solução de problemas (<em>problem solving</em>)</dt>
<dd>The process of formulating a problem, finding a solution, and expressing it.</dd>
<dt>linguagem de alto nível (<em>high-level language</em>)</dt>
<dd>A programming language like Python that is designed to be easy for humans to read and write.</dd>
<dt>linguagem de baixo nível (<em>low-level language</em>)</dt>
<dd>A programming language that is designed to be easy for a computer to run; also called “machine language” or “assembly language”.</dd>
<dt>portabilidade (<em>portability</em>)</dt>
<dd>A property of a program that can run on more than one kind of computer.</dd>
<dt>interpretador (<em>interpreter</em>)</dt>
<dd>A program that reads another program and executes it</dd>
<dt><em>prompt</em> (“sinal de pronto”)</dt>
<dd>Characters displayed by the interpreter to indicate that it is ready to take input from the user.</dd>
<dt>programação funcional (<em>program</em>)</dt>
<dd>A set of instructions that specifies a computation.</dd>
<dt><code class="docutils literal"><span class="pre">print</span></code>, instrução (<code class="docutils literal"><span class="pre">print</span></code> <em>statement</em>)</dt>
<dd>An instruction that causes the Python interpreter to display a value on the screen.</dd>
<dt>operador (<em>operator</em>)</dt>
<dd>A special symbol that represents a simple computation like addition, multiplication, or string concatenation.</dd>
<dt>valor (<em>value</em>)</dt>
<dd>One of the basic units of data, like a number or string, that a program manipulates.</dd>
<dt>tipo (<em>type</em>)</dt>
<dd>A category of values. The types we have seen so far are integers (type int), floating-point numbers (type float), and strings (type str).</dd>
<dt>inteiro (<em>integer</em>)</dt>
<dd>A type that represents whole numbers.</dd>
<dt>ponto-flutuante (<em>floating-point</em>)</dt>
<dd>A type that represents numbers with fractional parts.</dd>
<dt><em>string</em> (“cadeia de caracteres”)</dt>
<dd>A type that represents sequences of characters.</dd>
<dt>linguagem natural (<em>natural language</em>)</dt>
<dd>Any one of the languages that people speak that evolved naturally.</dd>
<dt>linguagem formal (<em>formal language</em>)</dt>
<dd>Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are formal languages.</dd>
<dt><em>token</em> (“símbolo”)</dt>
<dd>One of the basic elements of the syntactic structure of a program, analogous to a word in a natural language.</dd>
<dt>sintaxe (<em>syntax</em>)</dt>
<dd>The rules that govern the structure of a program.</dd>
<dt>analisar (<em>parse</em>)</dt>
<dd>To examine a program and analyze the syntactic structure.</dd>
<dt><em>bug</em></dt>
<dd>An error in a program.</dd>
<dt>depuração (<em>debugging</em>)</dt>
<dd>The process of finding and correcting bugs.</dd>
</dl>
</div>
<div class="section" id="exercises">
<h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this headline">¶</a></h2>
<p>It is a good idea to read this book in front of a computer so you can
try out the examples as you go.</p>
<p>Whenever you are experimenting with a new feature, you should try to
make mistakes. For example, in the “Hello, world!” program, what happens
if you leave out one of the quotation marks? What if you leave out both?
What if you spell print wrong?</p>
<p>This kind of experiment helps you remember what you read; it also helps
when you are programming, because you get to know what the error
messages mean. It is better to make mistakes now and on purpose than
later and accidentally.</p>
<ol class="arabic simple">
<li>In a print statement, what happens if you leave out one of the
parentheses, or both?</li>
<li>If you are trying to print a string, what happens if you leave out
one of the quotation marks, or both?</li>
<li>You can use a minus sign to make a negative number like -2. What
happens if you put a plus sign before a number? What about 2++2?</li>
<li>In math notation, leading zeros are ok, as in 02. What happens if you
try this in Python?</li>
<li>What happens if you have two values with no operator between them?</li>
</ol>
<p>Start the Python interpreter and use it as a calculator.</p>
<ol class="arabic simple">
<li>How many seconds are there in 42 minutes 42 seconds?</li>
<li>How many miles are there in 10 kilometers? Hint: there are 1.61
kilometers in a mile.</li>
<li>If you run a 10 kilometer race in 42 minutes 42 seconds, what is your
average pace (time per mile in minutes and seconds)? What is your
average speed in miles per hour?</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">The way of the program</a><ul>
<li><a class="reference internal" href="#what-is-a-program">What is a program?</a></li>
<li><a class="reference internal" href="#running-python">Running Python</a></li>
<li><a class="reference internal" href="#the-first-program">The first program</a></li>
<li><a class="reference internal" href="#arithmetic-operators">Arithmetic operators</a></li>
<li><a class="reference internal" href="#values-and-types">Values and types</a></li>
<li><a class="reference internal" href="#formal-and-natural-languages">Formal and natural languages</a></li>
<li><a class="reference internal" href="#debugging">Debugging</a></li>
<li><a class="reference internal" href="#glossary">Glossary</a></li>
<li><a class="reference internal" href="#exercises">Exercises</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="00-front-matter.html" title="previous chapter">Preface</a></li>
<li>Next: <a href="02-statement.html" title="next chapter">Variables, expressions and statements</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/01-the-way.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2015, Allen B. Downey.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.3.1</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.6</a>
|
<a href="_sources/01-the-way.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>