100% found this document useful (9 votes)
550 views61 pages

Fundamentals of Python First Programs 1st Edition Kenneth A. Lambert Download

The document is an overview of the book 'Fundamentals of Python: First Programs' by Kenneth A. Lambert, which covers essential concepts in Python programming and computer science. It includes chapters on algorithms, computer systems, software development, and control statements, along with exercises and case studies for practical learning. The book is published by Cengage Learning and is available in various digital formats.

Uploaded by

xcpguwhg2291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (9 votes)
550 views61 pages

Fundamentals of Python First Programs 1st Edition Kenneth A. Lambert Download

The document is an overview of the book 'Fundamentals of Python: First Programs' by Kenneth A. Lambert, which covers essential concepts in Python programming and computer science. It includes chapters on algorithms, computer systems, software development, and control statements, along with exercises and case studies for practical learning. The book is published by Cengage Learning and is available in various digital formats.

Uploaded by

xcpguwhg2291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Fundamentals of Python First Programs 1st

Edition Kenneth A. Lambert download

https://ebookname.com/product/fundamentals-of-python-first-
programs-1st-edition-kenneth-a-lambert/

Get the full ebook with Bonus Features for a Better Reading Experience on ebookname.com
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Python High Performance Programming Boost the


performance of your Python programs using advanced
techniques 1st Edition Gabriele Lanaro

https://ebookname.com/product/python-high-performance-
programming-boost-the-performance-of-your-python-programs-using-
advanced-techniques-1st-edition-gabriele-lanaro/

Programming Fundamentals A Modular Structured Approach


Using C Kenneth Leroy Busbee

https://ebookname.com/product/programming-fundamentals-a-modular-
structured-approach-using-c-kenneth-leroy-busbee/

Reflections of a Technocrat Managing Defense Air and


Space Programs During the 1st Edition John L. & Kenneth
J. Alnwick & Lawrence

https://ebookname.com/product/reflections-of-a-technocrat-
managing-defense-air-and-space-programs-during-the-1st-edition-
john-l-kenneth-j-alnwick-lawrence/

Selected Letters of C G Jung 1909 1961 C. G. Jung


(Editor)

https://ebookname.com/product/selected-letters-of-c-g-
jung-1909-1961-c-g-jung-editor/
A season in hell the life of Arthur Rimbaud Carré

https://ebookname.com/product/a-season-in-hell-the-life-of-
arthur-rimbaud-carre/

Weapons of Mass Instruction A Schoolteacher s Journey


through the Dark World of Compulsory Schooling John
Taylor Gatto

https://ebookname.com/product/weapons-of-mass-instruction-a-
schoolteacher-s-journey-through-the-dark-world-of-compulsory-
schooling-john-taylor-gatto/

Vowels and consonants 3rd Edition Peter Ladefoged

https://ebookname.com/product/vowels-and-consonants-3rd-edition-
peter-ladefoged/

C Programming From Problem Analysis to Program Design


2nd Edition Barbara Doyle

https://ebookname.com/product/c-programming-from-problem-
analysis-to-program-design-2nd-edition-barbara-doyle/

Transitions and Learning through the Lifecourse 1st


Edition Kathryn Ecclestone (Editor)

https://ebookname.com/product/transitions-and-learning-through-
the-lifecourse-1st-edition-kathryn-ecclestone-editor/
Victory over cancer Updated Edition M.D. Matthias Rath

https://ebookname.com/product/victory-over-cancer-updated-
edition-m-d-matthias-rath/
Fundamentals of
Python:
First Programs

Kenneth A. Lambert
Martin Osborne, Contributing Author

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Fundamentals of Python: First Programs © 2012 Course Technology, Cengage Learning
Kenneth A. Lambert ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
Executive Editor: Marie Lee
any means graphic, electronic, or mechanical, including but not limited to
Acquisitions Editor: Brandi Shailer photocopying, recording, scanning, digitizing, taping, Web distribution,
Senior Product Manager: Alyssa Pratt information networks, or information storage and retrieval systems, except
Development Editor: Ann Shaffer as permitted under Section 107 or 108 of the 1976 United States Copyright
Act, without the prior written permission of the publisher.
Associate Product Manager: Stephanie
Lorenz
For product information and technology assistance, contact us at
Associate Marketing Manager: Shanna
Cengage Learning Customer & Sales Support, 1-800-354-9706
Shelton
For permission to use material from this text or product, submit all
Content Project Manager: Jennifer Feltri requests online at www.cengage.com/permissions
Art Director: Faith Brosnan Further permissions questions can be emailed to
permissionrequest@cengage.com
Image credit: © istockphoto/Pei Ling Hoo
Cover Designer: Wing-ip Ngan,
Ink design, Inc. Library of Congress Control Number: 2011920241
Compositor: GEX Publishing Services ISBN-13: 978-1-111-82270-5
ISBN-10: 1-111-82270-0

Course Technology
20 Channel Center
Boston, Massachusetts 02210
USA

Cengage Learning is a leading provider of customized learning solutions


with office locations around the globe, including Singapore, the United
Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at:
international.cengage.com/region

Cengage Learning products are represented in Canada by Nelson


Education, Ltd.

For your lifelong learning solutions, visit course.cengage.com.

Purchase any of our products at your local college store or at our preferred
online store www.cengagebrain.com.

Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or regis-
tered trademarks of their respective manufacturers and sellers.

Any fictional data related to persons or companies or URLs used through-


out this book is intended for instructional purposes only. At the time this
book was printed, any such data was fictional and not belonging to any real
persons or companies.

Course Technology, a part of Cengage Learning, reserves the right to revise this
publication and make changes from time to time in its content without notice.

The programs in this book are for instructional purposes only.


They have been tested with care, but are not guaranteed for any particular
intent beyond educational purposes. The author and the publisher do not
offer any warranties or representations, nor do they accept any liabilities
Printed in the United States of America with respect to the programs.
1 2 3 4 5 6 7 15 14 13 12 11

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents
[CHAPTER] 1 INTRODUCTION 1
1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information
Processing .................................................................................................................2
1.1.1 Algorithms ................................................................................................2
1.1.2 Information Processing............................................................................4
1.1 Exercises....................................................................................................................5
1.2 The Structure of a Modern Computer System .......................................................6
1.2.1 Computer Hardware ................................................................................6
1.2.2 Computer Software..................................................................................8
1.2 Exercises..................................................................................................................10
1.3 A Not-So-Brief History of Computing Systems...................................................10
1.3.1 Before Electronic Digital Computers ...................................................11
1.3.2 The First Electronic Digital Computers (1940–1950) .........................15
1.3.3 The First Programming Languages (1950–1965).................................16
1.3.4 Integrated Circuits, Interaction, and Timesharing (1965–1975) .........18
1.3.5 Personal Computing and Networks (1975–1990) ................................19
1.3.6 Consultation, Communication, and Ubiquitous Computing
(1990–Present)........................................................................................21
1.4 Getting Started with Python Programming..........................................................23
1.4.1 Running Code in the Interactive Shell .................................................23
1.4.2 Input, Processing, and Output...............................................................25
1.4.3 Editing, Saving, and Running a Script ..................................................28
1.4.4 Behind the Scenes: How Python Works ...............................................29
1.4 Exercises..................................................................................................................30
1.5 Detecting and Correcting Syntax Errors...............................................................31
1.5 Exercises..................................................................................................................32
Suggestions for Further Reading ...........................................................................32
Summary .................................................................................................................33
Review Questions ...................................................................................................35
Projects....................................................................................................................37

[CHAPTER] 2 SOFTWARE DEVELOPMENT, DATA TYPES, AND


EXPRESSIONS 39
2.1 The Software Development Process .....................................................................40
2.1 Exercises..................................................................................................................43
2.2 Case Study: Income Tax Calculator.......................................................................43
2.2.1 Request ...................................................................................................43
2.2.2 Analysis ...................................................................................................44
2.2.3 Design.....................................................................................................44
2.2.4 Implementation (Coding) ......................................................................45
2.2.5 Testing ....................................................................................................46

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
2.3 Strings, Assignment, and Comments.....................................................................47
2.3.1 Data Types..............................................................................................47
2.3.2 String Literals.........................................................................................48
2.3.3 Escape Sequences ...................................................................................50
2.3.4 String Concatenation .............................................................................50
2.3.5 Variables and the Assignment Statement ..............................................51
2.3.6 Program Comments and Docstrings.....................................................52
2.3 Exercises..................................................................................................................53
2.4 Numeric Data Types and Character Sets ..............................................................54
2.4.1 Integers ...................................................................................................54
2.4.2 Floating-Point Numbers........................................................................55
2.4.3 Character Sets ........................................................................................55
2.4 Exercises..................................................................................................................57
2.5 Expressions .............................................................................................................58
2.5.1 Arithmetic Expressions ..........................................................................58
2.5.2 Mixed-Mode Arithmetic and Type Conversions ..................................60
2.5 Exercises..................................................................................................................63
2.6 Using Functions and Modules ...............................................................................63
2.6.1 Calling Functions: Arguments and Return Values................................64
2.6.2 The math Module .................................................................................65
2.6.3 The Main Module..................................................................................66
2.6.4 Program Format and Structure .............................................................67
2.6.5 Running a Script from a Terminal Command Prompt ........................68
2.6 Exercises..................................................................................................................70
Summary .................................................................................................................70
Review Questions ...................................................................................................72
Projects....................................................................................................................73

[CHAPTER] 3 CONTROL STATEMENTS 75


3.1 Definite Iteration: The for Loop.........................................................................76
3.1.1 Executing a Statement a Given Number of Times ..............................76
3.1.2 Count-Controlled Loops .......................................................................77
3.1.3 Augmented Assignment .........................................................................79
3.1.4 Loop Errors: Off-by-One Error............................................................80
3.1.5 Traversing the Contents of a Data Sequence........................................80
3.1.6 Specifying the Steps in the Range .........................................................81
3.1.7 Loops That Count Down ......................................................................82
3.1 Exercises..................................................................................................................83
3.2 Formatting Text for Output ...................................................................................83
3.2 Exercises..................................................................................................................86
3.3 Case Study: An Investment Report........................................................................87
3.3.1 Request ...................................................................................................87
3.3.2 Analysis ...................................................................................................87
3.3.3 Design.....................................................................................................88
3.3.4 Implementation (Coding) ......................................................................88
3.3.5 Testing ....................................................................................................90
3.4 Selection: if and if-else Statements ...............................................................91
3.4.1 The Boolean Type, Comparisons, and Boolean Expressions ...............91
3.4.2 if-else Statements .............................................................................92

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.4.3 One-Way Selection Statements.............................................................94
3.4.4 Multi-way if Statements ......................................................................95
3.4.5 Logical Operators and Compound Boolean Expressions.....................97
3.4.6 Short-Circuit Evaluation .......................................................................99
3.4.7 Testing Selection Statements ...............................................................100
3.4 Exercises................................................................................................................101
3.5 Conditional Iteration: The while Loop ............................................................102
3.5.1 The Structure and Behavior of a while Loop ..................................102
3.5.2 Count Control with a while Loop....................................................104
3.5.3 The while True Loop and the break Statement ..........................105
3.5.4 Random Numbers................................................................................107
3.5.5 Loop Logic, Errors, and Testing .........................................................109
3.5 Exercises................................................................................................................109
3.6 Case Study: Approximating Square Roots...........................................................110
3.6.1 Request .................................................................................................110
3.6.2 Analysis .................................................................................................110
3.6.3 Design...................................................................................................110
3.6.4 Implementation (Coding) ....................................................................112
3.6.5 Testing ..................................................................................................113
Summary ...............................................................................................................113
Review Questions .................................................................................................116
Projects..................................................................................................................118

[CHAPTER] 4 STRINGS AND TEXT FILES 121


4.1 Accessing Characters and Substrings in Strings..................................................122
4.1.1 The Structure of Strings......................................................................122
4.1.2 The Subscript Operator.......................................................................123
4.1.3 Slicing for Substrings ...........................................................................124
4.1.4 Testing for a Substring with the in Operator ....................................125
4.1 Exercises................................................................................................................126
4.2 Data Encryption ...................................................................................................126
4.2 Exercises................................................................................................................129
4.3 Strings and Number Systems...............................................................................129
4.3.1 The Positional System for Representing Numbers............................130
4.3.2 Converting Binary to Decimal ............................................................131
4.3.3 Converting Decimal to Binary ............................................................132
4.3.4 Conversion Shortcuts...........................................................................133
4.3.5 Octal and Hexadecimal Numbers .......................................................134
4.3 Exercises................................................................................................................136
4.4 String Methods .....................................................................................................136
4.4 Exercises................................................................................................................140
4.5 Text Files...............................................................................................................141
4.5.1 Text Files and Their Format................................................................141
4.5.2 Writing Text to a File ..........................................................................142
4.5.3 Writing Numbers to a File ..................................................................142
4.5.4 Reading Text from a File .....................................................................143
4.5.5 Reading Numbers from a File .............................................................145
4.5.6 Accessing and Manipulating Files and Directories on Disk...............146

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4.5 Exercises................................................................................................................148
4.6 Case Study: Text Analysis.....................................................................................148
4.6.1 Request .................................................................................................149
4.6.2 Analysis .................................................................................................149
4.6.3 Design...................................................................................................150
4.6.4 Implementation (Coding) ....................................................................151
4.6.5 Testing ..................................................................................................152
Summary ...............................................................................................................153
Review Questions .................................................................................................154
Projects..................................................................................................................156

[CHAPTER] 5 LISTS AND DICTIONARIES 159


5.1 Lists .......................................................................................................................160
5.1.1 List Literals and Basic Operators ........................................................160
5.1.2 Replacing an Element in a List ...........................................................163
5.1.3 List Methods for Inserting and Removing Elements .........................165
5.1.4 Searching a List....................................................................................167
5.1.5 Sorting a List........................................................................................168
5.1.6 Mutator Methods and the Value None ...............................................168
5.1.7 Aliasing and Side Effects......................................................................169
5.1.8 Equality: Object Identity and Structural Equivalence........................171
5.1.9 Example: Using a List to Find the Median of a Set of Numbers ......172
5.1.10 Tuples ...................................................................................................173
5.1 Exercises................................................................................................................174
5.2 Defining Simple Functions ..................................................................................175
5.2.1 The Syntax of Simple Function Definitions .......................................175
5.2.2 Parameters and Arguments..................................................................176
5.2.3 The return Statement.......................................................................177
5.2.4 Boolean Functions................................................................................177
5.2.5 Defining a main Function...................................................................178
5.2 Exercises................................................................................................................179
5.3 Case Study: Generating Sentences ......................................................................179
5.3.1 Request .................................................................................................179
5.3.2 Analysis .................................................................................................179
5.3.3 Design...................................................................................................180
5.3.4 Implementation (Coding) ....................................................................182
5.3.5 Testing ..................................................................................................183
5.4 Dictionaries...........................................................................................................183
5.4.1 Dictionary Literals ...............................................................................183
5.4.2 Adding Keys and Replacing Values .....................................................184
5.4.3 Accessing Values...................................................................................185
5.4.4 Removing Keys ....................................................................................186
5.4.5 Traversing a Dictionary .......................................................................186
5.4.6 Example: The Hexadecimal System Revisited....................................188
5.4.7 Example: Finding the Mode of a List of Values .................................189
5.4 Exercises................................................................................................................190

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
5.5 Case Study: Nondirective Psychotherapy ...........................................................191
5.5.1 Request .................................................................................................191
5.5.2 Analysis .................................................................................................191
5.5.3 Design...................................................................................................192
5.5.4 Implementation (Coding) ....................................................................193
5.5.5 Testing ..................................................................................................195
Summary ...............................................................................................................195
Review Questions .................................................................................................196
Projects..................................................................................................................198

[CHAPTER] 6 DESIGN WITH FUNCTIONS 201


6.1 Functions as Abstraction Mechanisms.................................................................202
6.1.1 Functions Eliminate Redundancy........................................................202
6.1.2 Functions Hide Complexity ................................................................203
6.1.3 Functions Support General Methods with Systematic Variations .....204
6.1.4 Functions Support the Division of Labor ...........................................205
6.1 Exercises................................................................................................................205
6.2 Problem Solving with Top-Down Design ...........................................................206
6.2.1 The Design of the Text-Analysis Program .........................................206
6.2.2 The Design of the Sentence-Generator Program ..............................207
6.2.3 The Design of the Doctor Program ...................................................209
6.2 Exercises................................................................................................................210
6.3 Design with Recursive Functions ........................................................................211
6.3.1 Defining a Recursive Function ............................................................211
6.3.2 Tracing a Recursive Function ..............................................................213
6.3.3 Using Recursive Definitions to Construct Recursive Functions .......214
6.3.4 Recursion in Sentence Structure .........................................................214
6.3.5 Infinite Recursion.................................................................................215
6.3.6 The Costs and Benefits of Recursion..................................................216
6.3 Exercises................................................................................................................218
6.4 Case Study: Gathering Information from a File System ....................................219
6.4.1 Request .................................................................................................219
6.4.2 Analysis .................................................................................................220
6.4.3 Design...................................................................................................222
6.4.4 Implementation (Coding) ....................................................................224
6.5 Managing a Program’s Namespace ......................................................................227
6.5.1 Module Variables, Parameters, and Temporary Variables ..................227
6.5.2 Scope.....................................................................................................228
6.5.3 Lifetime ................................................................................................229
6.5.4 Default (Keyword) Arguments ............................................................230
6.5 Exercises................................................................................................................232
6.6 Higher-Order Functions (Advanced Topic) ........................................................233
6.6.1 Functions as First-Class Data Objects ................................................233
6.6.2 Mapping................................................................................................234
6.6.3 Filtering ................................................................................................236
6.6.4 Reducing...............................................................................................237
6.6.5 Using lambda to Create Anonymous Functions...............................237
6.6.6 Creating Jump Tables ..........................................................................238

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6.6 Exercises................................................................................................................239
Summary ...............................................................................................................240
Review Questions .................................................................................................242
Projects..................................................................................................................244

[CHAPTER] 7 SIMPLE GRAPHICS AND IMAGE PROCESSING 247


7.1 Simple Graphics ...................................................................................................248
7.1.1 Overview of Turtle Graphics ...............................................................248
7.1.2 Turtle Operations.................................................................................249
7.1.3 Object Instantiation and the turtle Module ...................................252
7.1.4 Drawing Two-Dimensional Shapes .....................................................254
7.1.5 Taking a Random Walk........................................................................255
7.1.6 Colors and the RGB System................................................................256
7.1.7 Example: Drawing with Random Colors ............................................257
7.1.8 Examining an Object’s Attributes ........................................................259
7.1.9 Manipulating a Turtle’s Screen ............................................................259
7.1.10 Setting up a cfg File and Running IDLE..........................................260
7.1 Exercises................................................................................................................261
7.2 Case Study: Recursive Patterns in Fractals..........................................................262
7.2.1 Request .................................................................................................263
7.2.2 Analysis .................................................................................................263
7.2.3 Design...................................................................................................264
7.2.4 Implementation (Coding) ....................................................................266
7.3 Image Processing .................................................................................................267
7.3.1 Analog and Digital Information .........................................................267
7.3.2 Sampling and Digitizing Images .........................................................268
7.3.3 Image File Formats ..............................................................................268
7.3.4 Image-Manipulation Operations .........................................................269
7.3.5 The Properties of Images ....................................................................270
7.3.6 The images Module ..........................................................................270
7.3.7 A Loop Pattern for Traversing a Grid ................................................274
7.3.8 A Word on Tuples................................................................................275
7.3.9 Converting an Image to Black and White ..........................................276
7.3.10 Converting an Image to Grayscale......................................................278
7.3.11 Copying an Image ................................................................................279
7.3.12 Blurring an Image ................................................................................280
7.3.13 Edge Detection ....................................................................................281
7.3.14 Reducing the Image Size .....................................................................282
7.3 Exercises................................................................................................................284
Summary ...............................................................................................................285
Review Questions .................................................................................................286
Projects..................................................................................................................288

[CHAPTER] 8 DESIGN WITH CLASSES 293


8.1 Getting Inside Objects and Classes .....................................................................294
8.1.1 A First Example: The Student Class................................................295
8.1.2 Docstrings ............................................................................................298
8.1.3 Method Definitions..............................................................................298

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
8.1.4 The __init__ Method and Instance Variables................................299
8.1.5 The __str__ Method........................................................................300
8.1.6 Accessors and Mutators .......................................................................300
8.1.7 The Lifetime of Objects ......................................................................301
8.1.8 Rules of Thumb for Defining a Simple Class.....................................302
8.1 Exercises................................................................................................................303
8.2 Case Study: Playing the Game of Craps .............................................................303
8.2.1 Request .................................................................................................303
8.2.2 Analysis .................................................................................................303
8.2.3 Design...................................................................................................304
8.2.4 Implementation (Coding) ....................................................................306
8.3 Data-Modeling Examples.....................................................................................309
8.3.1 Rational Numbers ................................................................................309
8.3.2 Rational Number Arithmetic and Operator Overloading..................311
8.3.3 Comparison Methods...........................................................................312
8.3.4 Equality and the __eq__ Method ......................................................314
8.3.5 Savings Accounts and Class Variables .................................................315
8.3.6 Putting the Accounts into a Bank........................................................317
8.3.7 Using pickle for Permanent Storage of Objects.............................319
8.3.8 Input of Objects and the try-except Statement............................320
8.3.9 Playing Cards .......................................................................................321
8.3 Exercises................................................................................................................325
8.4 Case Study: An ATM............................................................................................325
8.4.1 Request .................................................................................................325
8.4.2 Analysis .................................................................................................325
8.4.3 Design...................................................................................................327
8.4.4 Implementation (Coding) ....................................................................329
8.5 Structuring Classes with Inheritance and Polymorphism...................................331
8.5.1 Inheritance Hierarchies and Modeling ...............................................332
8.5.2 Example: A Restricted Savings Account..............................................333
8.5.3 Example: The Dealer and a Player in the Game of Blackjack ...........335
8.5.4 Polymorphic Methods..........................................................................340
8.5.5 Abstract Classes ...................................................................................340
8.5.6 The Costs and Benefits of Object-Oriented Programming...............341
8.5 Exercises................................................................................................................343
Summary ...............................................................................................................343
Review Questions .................................................................................................345
Projects..................................................................................................................346

[CHAPTER] 9 GRAPHICAL USER INTERFACES 349


9.1 The Behavior of Terminal-Based Programs and GUI-Based Programs............350
9.1.1 The Terminal-Based Version ...............................................................350
9.1.2 The GUI-Based Version......................................................................351
9.1.3 Event-Driven Programming................................................................353
9.1 Exercises................................................................................................................355
9.2 Coding Simple GUI-Based Programs .................................................................355
9.2.1 Windows and Labels............................................................................356
9.2.2 Displaying Images ................................................................................357
9.2.3 Command Buttons and Responding to Events...................................358
9.2.4 Viewing the Images of Playing Cards .................................................360

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
9.2.5 Entry Fields for the Input and Output of Text ...................................363
9.2.6 Using Pop-up Dialog Boxes ................................................................365
9.2 Exercises................................................................................................................366
9.3 Case Study: A GUI-Based ATM..........................................................................367
9.3.1 Request .................................................................................................367
9.3.2 Analysis .................................................................................................367
9.3.3 Design...................................................................................................368
9.3.4 Implementation (Coding) ....................................................................369
9.4 Other Useful GUI Resources ..............................................................................372
9.4.1 Colors ...................................................................................................373
9.4.2 Text Attributes......................................................................................373
9.4.3 Sizing and Justifying an Entry .............................................................374
9.4.4 Sizing the Main Window.....................................................................375
9.4.5 Grid Attributes .....................................................................................376
9.4.6 Using Nested Frames to Organize Components................................380
9.4.7 Multi-Line Text Widgets .....................................................................381
9.4.8 Scrolling List Boxes .............................................................................384
9.4.9 Mouse Events .......................................................................................387
9.4.10 Keyboard Events ..................................................................................388
9.4 Exercises................................................................................................................389
Summary ...............................................................................................................390
Review Questions .................................................................................................391
Projects..................................................................................................................392

[CHAPTER] 10 MULTITHREADING, NETWORKS, AND CLIENT/SERVER


PROGRAMMING 395
10.1 Threads and Processes .........................................................................................396
10.1.1 Threads.................................................................................................397
10.1.2 Sleeping Threads..................................................................................400
10.1.3 Producer, Consumer, and Synchronization ........................................402
10.1 Exercises................................................................................................................409
10.2 Networks, Clients, and Servers............................................................................409
10.2.1 IP Addresses .........................................................................................409
10.2.2 Ports, Servers, and Clients...................................................................411
10.2.3 Sockets and a Day/Time Client Script................................................412
10.2.4 A Day/Time Server Script ...................................................................414
10.2.5 A Two-Way Chat Script.......................................................................416
10.2.6 Handling Multiple Clients Concurrently ...........................................418
10.2.7 Setting Up Conversations for Others .................................................420
10.2 Exercises................................................................................................................422
10.3 Case Study: A Multi-Client Chat Room .............................................................423
10.3.1 Request ................................................................................................423
10.3.2 Analysis ................................................................................................423
10.3.3 Design...................................................................................................424
10.3.4 Implementation (Coding) ....................................................................425
Summary ...............................................................................................................427
Review Questions .................................................................................................428
Projects..................................................................................................................430

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
[ONLINE CHAPTER] 11 SEARCHING, SORTING, AND COMPLEXITY ANALYSIS

11.1 Measuring the Efficiency of Algorithms


11.1.1 Measuring the Run Time of an Algorithm
11.1.2 Counting Instructions
11.1.3 Measuring the Memory Used by an Algorithm
11.1 Exercises
11.2 Complexity Analysis
11.2.1 Orders of Complexity
11.2.2 Big-O Notation
11.2.3 The Role of the Constant of Proportionality
11.2 Exercises
11.3 Search Algorithms
11.3.1 Search for a Minimum
11.3.2 Linear Search of a List
11.3.3 Best-Case, Worst-Case, and Average-Case Performance
11.3.4 Binary Search of a List
11.3.5 Comparing Data Items
11.3 Exercises
11.4 Sort Algorithms
11.4.1 Selection Sort
11.4.2 Bubble Sort
11.4.3 Insertion Sort
11.4.4 Best-Case, Worst-Case, and Average-Case Performance Revisited
11.4 Exercises
11.5 An Exponential Algorithm: Recursive Fibonacci
11.6 Converting Fibonacci to a Linear Algorithm
11.7 Case Study: An Algorithm Profiler
11.7.1 Request
11.7.2 Analysis
11.7.3 Design
11.7.4 Implementation (Coding)
Summary
Review Questions
Projects

[APPENDIX] A PYTHON RESOURCES 433


A.1 Installing Python on Your Computer ..................................................................434
A.2 Using the Terminal Command Prompt, IDLE, and Other IDEs......................434

[APPENDIX] B INSTALLING THE images LIBRARY 437


[APPENDIX] C API FOR IMAGE PROCESSING 439
[APPENDIX] D TRANSITION FROM PYTHON TO JAVA AND C++ 441
GLOSSARY 443
INDEX 455
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
PREFACE
Welcome to Fundamentals of Python: First Programs. This text is intended for a
course in programming and problem-solving. It covers the material taught in a
typical Computer Science 1 course (CS1) at the undergraduate level.
This book covers five major aspects of computing:
1 Programming Basics—Data types, control structures, algorithm devel-
opment, and program design with functions are basic ideas that you need
to master in order to solve problems with computers. This book exam-
ines these core topics in detail and gives you practice employing your
understanding of them to solve a wide range of problems.
2 Object-Oriented Programming (OOP)—Object-Oriented
Programming is the dominant programming paradigm used to develop
large software systems. This book introduces you to the fundamental
principles of OOP and enables you to apply them successfully.
3 Data and Information Processing—Most useful programs rely on data
structures to solve problems. These data structures include strings,
arrays, files, lists, and dictionaries. This book introduces you to these
commonly used data structures, with examples that illustrate criteria for
selecting the appropriate data structures for given problems.
4 Software Development Life Cycle—Rather than isolate software
development techniques in one or two chapters, this book deals with
them throughout in the context of numerous case studies. Among other
things, you’ll learn that coding a program is often not the most difficult
or challenging aspect of problem solving and software development.
5 Contemporary Applications of Computing—The best way to learn
about programming and problem solving is to create interesting programs
with real-world applications. In this book, you’ll begin by creating applica-
tions that involve numerical problems and text processing. For example,
you’ll learn the basics of encryption techniques such as those that are used
to make your credit card number and other information secure on the
Internet. But unlike many other introductory texts, this one does not
restrict itself to problems involving numbers and text. Most contemporary
applications involve graphical user interfaces, event-driven programming,
graphics, and network communications. These topics are presented in
optional, standalone chapters.

PREFACE [ xiii ]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Why Python?
Computer technology and applications have become increasingly more sophisti-
cated over the past two decades, and so has the computer science curriculum, espe-
cially at the introductory level. Today’s students learn a bit of programming and
problem–solving, and are then expected to move quickly into topics like software
development, complexity analysis, and data structures that, twenty years ago, were
relegated to advanced courses. In addition, the ascent of object-oriented program-
ming as the dominant paradigm of problem solving has led instructors and text-
book authors to bring powerful, industrial-strength programming languages such as
C++ and Java into the introductory curriculum. As a result, instead of experiencing
the rewards and excitement of solving problems with computers, beginning com-
puter science students often become overwhelmed by the combined tasks of mas-
tering advanced concepts as well as the syntax of a programming language.
This book uses the Python programming language as a way of making the
first year of computer science more manageable and attractive for students and
instructors alike. Python has the following pedagogical benefits:
 Python has simple, conventional syntax. Python statements are very close to

those of pseudocode algorithms, and Python expressions use the conven-


tional notation found in algebra. Thus, students can spend less time learn-
ing the syntax of a programming language and more time learning to solve
interesting problems.
 Python has safe semantics. Any expression or statement whose meaning

violates the definition of the language produces an error message.


 Python scales well. It is very easy for beginners to write simple programs in

Python. Python also includes all of the advanced features of a modern pro-
gramming language, such as support for data structures and object-oriented
software development, for use when they become necessary.
 Python is highly interactive. Expressions and statements can be entered at

an interpreter’s prompts to allow the programmer to try out experimental


code and receive immediate feedback. Longer code segments can then be
composed and saved in script files to be loaded and run as modules or
standalone applications.
 Python is general purpose. In today’s context, this means that the language

includes resources for contemporary applications, including media comput-


ing and networks.
 Python is free and is in widespread use in industry. Students can download

Python to run on a variety of devices. There is a large Python user com-


munity, and expertise in Python programming has great resume value.

[ xiv ] PREFACE

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
To summarize these benefits, Python is a comfortable and flexible vehicle for
expressing ideas about computation, both for beginners and for experts as well. If
students learn these ideas well in the first course, they should have no problems
making a quick transition to other languages needed for courses later in the cur-
riculum. Most importantly, beginning students will spend less time staring at a
computer screen and more time thinking about interesting problems to solve.

Organization of the Book


The approach of this text is easygoing, with each new concept introduced only
when it is needed.
Chapter 1 introduces computer science by focusing on two fundamental
ideas, algorithms and information processing. A brief overview of computer hard-
ware and software, followed by an extended discussion of the history of comput-
ing, sets the context for computational problem solving.
Chapters 2 and 3 cover the basics of problem solving and algorithm develop-
ment using the standard control structures of expression evaluation, sequencing,
Boolean logic, selection, and iteration with the basic numeric data types.
Emphasis in these chapters is on problem solving that is both systematic and
experimental, involving algorithm design, testing, and documentation.
Chapters 4 and 5 introduce the use of the strings, text files, lists, and diction-
aries. These data structures are both remarkably easy to manipulate in Python
and support some interesting applications. Chapter 5 also introduces simple func-
tion definitions as a way of organizing algorithmic code.
Chapter 6 explores the technique and benefits of procedural abstraction with
function definitions. Top-down design, stepwise refinement, and recursive design
with functions are examined as means of structuring code to solve complex prob-
lems. Details of namespace organization (parameters, temporary variables, and
module variables) and communication among software components are discussed.
An optional section on functional programming with higher-order functions
shows how to exploit functional design patterns to simplify solutions.
Chapter 7 focuses on the use of existing objects and classes to compose pro-
grams. Special attention is paid to the interface, or set of methods, of a class of
objects and the manner in which objects cooperate to solve problems. This chapter
also introduces two contemporary applications of computing, graphics and image
processing—areas in which object-based programming is particularly useful.

PREFACE [ xv ]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Chapter 8 introduces object-oriented design with class and method defini-
tions. Several examples of simple class definitions from different application
domains are presented. Some of these are then integrated into more realistic
applications, to show how object-oriented software components can be used to
build complex systems. Emphasis is on designing appropriate interfaces for
classes that exploit inheritance and polymorphism.
Chapters 9 and 10 cover advanced material related to two important areas of
computing: graphical user interfaces and networks. Although these two chapters
are entirely optional, they give students challenging experiences at the end of the
first course. Chapter 9 contrasts the event-driven model of GUI programs with
the process-driven model of terminal-based programs. The creation and layout of
GUI components are explored, as well as the decomposition of a GUI-based pro-
gram using the model/view/controller pattern. Chapter 10 introduces multi-
threaded programs and the construction of simple network-based client/server
applications.
Chapter 11 covers some topics addressed at the beginning of a traditional
CS2 course, and is available on the publisher’s Web site. This chapter introduces
complexity analysis with big-O notation. Enough material is presented to enable
you to perform simple analyses of the running time and memory usage of algo-
rithms and data structures, using search and sort algorithms as examples.

Special Features
This book explains and develops concepts carefully, using frequent examples and
diagrams. New concepts are then applied in complete programs to show how
they aid in solving problems. The chapters place an early and consistent emphasis
on good writing habits and neat, readable documentation.
The book includes several other important features:
 Case studies—These present complete Python programs ranging from the

simple to the substantial. To emphasize the importance and usefulness of


the software development life cycle, case studies are discussed in the frame-
work of a user request, followed by analysis, design, implementation, and
suggestions for testing, with well-defined tasks performed at each stage.
Some case studies are extended in end-of-chapter programming projects.
 Chapter objectives and chapter summaries—Each chapter begins with a set

of learning objectives and ends with a summary of the major concepts cov-
ered in the chapter.
 Key terms and a glossary—When a technical term is introduced in the text,

it appears in boldface. Definitions of the key terms are also collected in a


glossary.

[ xvi ] PREFACE

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
 Exercises—Most major sections of each chapter end with exercise ques-
tions that reinforce the reading by asking basic questions about the mate-
rial in the section. Each chapter ends with a set of review exercises.
 Programming projects—Each chapter ends with a set of programming
projects of varying difficulty.
 A software toolkit for image processing—This book comes with an open-
source Python toolkit for the easy image processing discussed in Chapter 7.
The toolkit can be obtained from the student downloads page on
www.course.com, or at http://home.wlu.edu/~lambertk/python/
 Appendices—Three appendices include information on obtaining Python
resources, installing the toolkit, and using the toolkit’s interface.

Supplemental Resources
The following supplemental materials are available when this book is used in a
classroom setting. All of the teaching tools available with this book are provided
to the instructor on a single CD-ROM.

Electronic Instructor’s Manual


The Instructor’s Manual that accompanies this textbook includes:
 Additional instructional material to assist in class preparation, including

suggestions for lecture topics.


 Solutions to all the end-of-chapter materials, including the Programming

Exercises.

ExamView®
This textbook is accompanied by ExamView, a powerful testing software package
that allows instructors to create and administer printed, computer (LAN-based),
and Internet exams. ExamView includes hundreds of questions that correspond to
the topics covered in this text, enabling students to generate detailed study guides
that include page references for further review. These computer-based and
Internet testing components allow students to take exams at their computers, and
save the instructor time because each exam is graded automatically.

PowerPoint Presentations
This book comes with Microsoft PowerPoint slides for each chapter. These are
included as a teaching aid either to make available to students on the network for
chapter review, or to be used during classroom presentations. Instructors can
modify slides or add their own slides to tailor their presentations.

PREFACE [ xvii ]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Distance Learning
Course Technology is proud to offer online courses in WebCT and Blackboard.
For more information on how to bring distance learning to your course, contact
your local Cengage Learning sales representative.

Source Code
The source code is available at www.cengagebrain.com—and also is available on the
Instructor Resources CD-ROM. If an input file is needed to run a program, it is
included with the source code.

Solution files
The solution files for all programming exercises are available at www.cengagebrain.com
and are available on the Instructor Resources CD-ROM. If an input file is needed to
run a programming exercise, it is included with the solution file.

We Appreciate Your Feedback


We have tried to produce a high-quality text, but should you encounter any
errors, please report them to lambertk@wlu.edu or computerscience@cengage.com. A
list of errata, should they be found, as well as other information about the book,
will be posted on the Web site http://home.wlu.edu/~lambertk/python/ and with the
student resources at www.cengagebrain.com.

Acknowledgments
I would like to thank my contributing author, Martin Osborne, for many years of
advice, friendly criticism, and encouragement on several of my book projects. To
my colleague, Joshua Stough, and our students at Washington and Lee University for
classroom testing this book over several semesters.
In addition, I would like to thank the following reviewers for the time and
effort they contributed to Fundamentals of Python: Paul Albee, Central Michigan
University; Andrew Danner, Swarthmore College; Susan Fox, Macalester
College; Robert Franks, Central College; and Jim Slack, Minnesota State
University, Mankato. Also, thank you to the following reviewers who contributed
their thoughts on the original book proposal: Christian Blouin, Dalhousie
University; Margaret Iwobi, Binghamton University; Sam Midkiff, Purdue
University; and Ray Morehead, West Virginia University.

[ xviii ] PREFACE

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Also, thank you to the individuals at Course Technology who helped to assure
that the content of all data and solution files used for this text were correct and
accurate: Chris Scriver, MQA Project Leader and Serge Palladino, MQA Tester.
Finally, thanks to several other people whose work made this book possible:
Ann Shaffer, Developmental Editor; Brandi Shailer, Acquisitions Editor, Course
Technology; Alyssa Pratt, Senior Product Manager, Course Technology; and
Jennifer Feltri, Content Project Manager, Course Technology.

Dedication
To my students in Computer Science 111
Kenneth A. Lambert
Lexington, VA

PREFACE [ xix ]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
[CHAPTER]
1 Introduction
After completing this chapter, you will be able to
 Describe the basic features of an algorithm
 Explain how hardware and software collaborate in a com-
puter’s architecture
 Give a brief history of computing
Compose and run a simple Python program


As a reader of this book, you almost certainly have played a


video game and listened to music on a CD player. It’s likely that you
have watched a movie on a DVD player and prepared a snack in a
microwave oven. Chances are that you have made at least one phone
call to or from a cell phone. You and your friends have most likely
used a desktop computer or a laptop computer, not to mention digi-
tal cameras and handheld music and video players.
All of these devices have something in common: they are or
contain computers. Computer technology makes them what they
are. Devices that rely on computer technology are almost every-
where, not only in our homes, but also in our schools, where we
work, and where we play. Computer technology plays an important
role in entertainment, education, medicine, manufacturing, commu-
nications, government, and commerce. It has been said that we have
digital lifestyles and that we live in an information age with an infor-
mation-based economy. Some people even claim that nature itself
performs computations on information structures present in DNA
and in the relationships among subatomic particles.
It’s difficult to imagine our world without computers, although
we don’t think about the actual computers very much. It’s also hard
to imagine that the human race did without computer technology

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
for thousands of years, and that the world as we know it has been so involved in
and with computer technology for only the past 25 years or so.
In the chapters that follow, you will learn about computer science, which is
the study of computation that has made this new technology and this new world
possible. You will also learn how to use computers effectively and appropriately to
enhance your own life and the lives of others.

1.1 Two Fundamental Ideas of Computer


Science: Algorithms and Information
Processing
Like most areas of study, computer science focuses on a broad set of interrelated
ideas. Two of the most basic ones are algorithms and information processing.
In this section, these ideas are introduced in an informal way. We will examine
them in more detail in later chapters.

1.1.1 Algorithms
People computed long before the invention of modern computing devices, and
many continue to use computing devices that we might consider primitive. For
example, consider how merchants made change for customers in marketplaces
before the existence of credit cards, pocket calculators, or cash registers. Making
change can be a complex activity. It probably took you some time to learn how to
do it, and it takes some mental effort to get it right every time. Let’s consider
what’s involved in this process.
The first step is to compute the difference between the purchase price and
the amount of money that the customer gives the merchant. The result of this
calculation is the total amount that the merchant must return to the purchaser.
For example, if you buy a dozen eggs at the farmers’ market for $2.39 and you
give the farmer a $10 bill, she should return $7.61 to you. To produce this
amount, the merchant selects the appropriate coins and bills that, when added to
$2.39, make $10.00.
Few people can subtract three-digit numbers without resorting to some man-
ual aids, such as pencil and paper. As you learned in grade school, you can carry
out subtraction with pencil and paper by following a sequence of well-defined
steps. You have probably done this many times but never made a list of the

[2] CHAPTER 1 Introduction

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
specific steps involved. Making such lists to solve problems is something com-
puter scientists do all the time. For example, the following list of steps describes
the process of subtracting two numbers using a pencil and paper:
Step 1 Write down the two numbers, with the larger number above the
smaller number and their digits aligned in columns from the right.
Step 2 Assume that you will start with the rightmost column of digits and
work your way left through the various columns.
Step 3 Write down the difference between the two digits in the current
column of digits, borrowing a 1 from the top number’s next column
to the left if necessary.
Step 4 If there is no next column to the left, stop. Otherwise, move to the
next column to the left, and go to Step 3.
If the computing agent (in this case a human being) follows each of these
simple steps correctly, the entire process results in a correct solution to the given
problem. We assume in Step 3 that the agent already knows how to compute the
difference between the two digits in any given column, borrowing if necessary.
To make change, most people can select the combination of coins and bills
that represent the correct change amount without any manual aids, other than
the coins and bills. But the mental calculations involved can still be described in a
manner similar to the preceding steps, and we can resort to writing them down
on paper if there is a dispute about the correctness of the change.
The sequence of steps that describes each of these computational processes is
called an algorithm. Informally, an algorithm is like a recipe. It provides a set of
instructions that tells us how to do something, such as make change, bake bread,
or put together a piece of furniture. More precisely, an algorithm describes a
process that ends with a solution to a problem. The algorithm is also one of the
fundamental ideas of computer science. An algorithm has the following features:
1 An algorithm consists of a finite number of instructions.
2 Each individual instruction in an algorithm is well defined. This means that
the action described by the instruction can be performed effectively or be
executed by a computing agent. For example, any computing agent capa-
ble of arithmetic can compute the difference between two digits. So an
algorithmic step that says “compute the difference between two digits”
would be well defined. On the other hand, a step that says “divide a number
by 0” is not well defined, because no computing agent could carry it out.

1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing [3]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3 An algorithm describes a process that eventually halts after arriving at a
solution to a problem. For example, the process of subtraction halts after
the computing agent writes down the difference between the two digits
in the leftmost column of digits.
4 An algorithm solves a general class of problems. For example, an algo-
rithm that describes how to make change should work for any two
amounts of money whose difference is greater than or equal to $0.00.
Creating a list of steps that describe how to make change might not seem like
a major accomplishment to you. But the ability to break a task down into its com-
ponent parts is one of the main jobs of a computer programmer. Once we write
an algorithm to describe a particular type of computation, a machine can be built
to do the computing. Put another way, if we can develop an algorithm to solve a
problem, we can automate the task of solving the problem. You might not feel
compelled to write a computer program to automate the task of making change,
because you can probably already make change yourself fairly easily. But suppose
you needed to do a more complicated task—such as sorting a list of 100 names.
In that case, a computer program would be very handy.
Computers can be designed to run a small set of algorithms for performing
specialized tasks such as operating a microwave oven. But we can also build com-
puters, like the one on your desktop, that are capable of performing a task
described by any algorithm. These computers are truly general-purpose problem-
solving machines. They are unlike any machines we have ever built before, and
they have formed the basis of the completely new world in which we live.
Later in this book, we introduce a notation for expressing algorithms and
some suggestions for designing algorithms. You will see that algorithms and algo-
rithmic thinking are critical underpinnings of any computer system.

1.1.2 Information Processing


Since human beings first learned to write several thousand years ago, they have
processed information. Information itself has taken many forms in its history, from
the marks impressed on clay tablets in ancient Mesopotamia, to the first written
texts in ancient Greece, to the printed words in the books, newspapers, and maga-
zines mass-produced since the European Renaissance, to the abstract symbols of
modern mathematics and science used during the past 350 years. Only recently,
however, have human beings developed the capacity to automate the processing of
information by building computers. In the modern world of computers, informa-
tion is also commonly referred to as data. But what is information?

[4] CHAPTER 1 Introduction

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Like mathematical calculations, information processing can be described with
algorithms. In our earlier example of making change, the subtraction steps
involved manipulating symbols used to represent numbers and money. In carry-
ing out the instructions of any algorithm, a computing agent manipulates infor-
mation. The computing agent starts with some given information (known as
input), transforms this information according to well-defined rules, and produces
new information, known as output.
It is important to recognize that the algorithms that describe information
processing can also be represented as information. Computer scientists have been
able to represent algorithms in a form that can be executed effectively and effi-
ciently by machines. They have also designed real machines, called electronic
digital computers, which are capable of executing algorithms.
Computer scientists more recently discovered how to represent many other
things, such as images, music, human speech, and video, as information. Many of
the media and communication devices that we now take for granted would be
impossible without this new kind of information processing. We examine many of
these achievements in more detail in later chapters.

1.1 Exercises
These short end-of-section exercises are intended to stimulate your thinking
about computing.
1 List three common types of computing agents.
2 Write an algorithm that describes the second part of the process of mak-
ing change (counting out the coins and bills).
3 Write an algorithm that describes a common task, such as baking a cake
or operating a DVD player.
4 Describe an instruction that is not well defined and thus could not be
included as a step in an algorithm. Give an example of such an instruction.
5 In what sense is a desktop computer a general-purpose problem-solving
machine?
6 List four devices that use computers and describe the information that
they process. (Hint: Think of the inputs and outputs of the devices.)

1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing [5]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
1.2 The Structure of a Modern Computer
System
We now give a brief overview of the structure of modern computer systems. A
modern computer system consists of hardware and software. Hardware consists
of the physical devices required to execute algorithms. Software is the set of these
algorithms, represented as programs in particular programming languages. In
the discussion that follows, we focus on the hardware and software found in a
typical desktop computer system, although similar components are also found in
other computer systems, such as handheld devices and ATMs (automatic teller
machines).

1.2.1 Computer Hardware


The basic hardware components of a computer are memory, a central processing
unit (CPU), and a set of input/output devices, as shown in Figure 1.1.

Input device Output device

Memory

CPU

[FIGURE 1.1] Hardware components of a modern computer system


Human users primarily interact with the input and output devices. The input
devices include a keyboard, a mouse, and a microphone. Common output devices
include a monitor and speakers. Computers can also communicate with the exter-
nal world through various ports that connect them to networks and to other
devices such as handheld music players and digital cameras. The purpose of most
of the input devices is to convert information that human beings deal with, such
as text, images, and sounds, into information for computational processing. The
purpose of most output devices is to convert the results of this processing back to
human-usable form.

[6] CHAPTER 1 Introduction

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Computer memory is set up to represent and store information in electronic
form. Specifically, information is stored as patterns of binary digits (1s and 0s).
To understand how this works, consider a basic device such as a light switch,
which can only be in one of two states, on or off. Now suppose there is a bank of
switches that control 16 small lights in a row. By turning the switches off or on,
we can represent any pattern of 16 binary digits (1s and 0s) as patterns of lights
that are on or off. As we will see later in this book, computer scientists have dis-
covered how to represent any information, including text, images, and sound, in
binary form.
Now, suppose there are 8 of these groups of 16 lights. We can select any
group of lights and examine or change the state of each light within that collec-
tion. We have just developed a tiny model of computer memory. This memory
has 8 cells, each of which can store 16 bits of binary information. A diagram of
this model, in which the memory cells are filled with binary digits, is shown in
Figure 1.2. This memory is also sometimes called primary or internal or
random access memory (RAM).

Cell 7 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1
Cell 6 1 0 1 1 0 1 1 1 1 1 1 0 1 1 1 1
Cell 5 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1
Cell 4 1 0 1 1 1 0 1 1 1 1 1 1 0 1 1 1
Cell 3 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1
Cell 2 0 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1
Cell 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1
Cell 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0

[FIGURE 1.2] A model of computer memory


The information stored in memory can represent any type of data, such as
numbers, text, images, or sound, or the instructions of a program. We can also
store in memory an algorithm encoded as binary instructions for the computer.
Once the information is stored in memory, we typically want to do something
with it—that is, we want to process it. The part of a computer that is responsible
for processing data is the central processing unit (CPU). This device, which is
also sometimes called a processor, consists of electronic switches arranged to
perform simple logical, arithmetic, and control operations. The CPU executes an
algorithm by fetching its binary instructions from memory, decoding them, and
executing them. Executing an instruction might involve fetching other binary
information—the data—from memory as well.

1.2 The Structure of a Modern Computer System [7]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
The processor can locate data in a computer’s primary memory very quickly.
However, these data exist only as long as electric power comes into the computer.
If the power fails or is turned off, the data in primary memory are lost. Clearly, a
more permanent type of memory is needed to preserve data. This more perma-
nent type of memory is called external or secondary memory, and it comes in
several forms. Magnetic storage media, such as tapes and hard disks, allow bit
patterns to be stored as patterns on a magnetic field. Semiconductor storage
media, such as flash memory sticks, perform much the same function with a dif-
ferent technology, as do optical storage media, such as CDs and DVDs. Some
of these secondary storage media can hold much larger quantities of information
than the internal memory of a computer.

1.2.2 Computer Software


You have learned that a computer is a general-purpose, problem-solving machine.
To solve any computable problem, a computer must be capable of executing any
algorithm. Because it is impossible to anticipate all of the problems for which
there are algorithmic solutions, there is no way to “hardwire” all potential algo-
rithms into a computer’s hardware. Instead, we build some basic operations into
the hardware’s processor and require any algorithm to use them. The algorithms
are converted to binary form and then loaded, with their data, into the com-
puter’s memory. The processor can then execute the algorithms’ instructions by
running the hardware’s more basic operations.
Any programs that are stored in memory so that they can be executed later
are called software. A program stored in computer memory must be represented
in binary digits, which is also known as machine code. Loading machine code
into computer memory one digit at a time would be a tedious, error-prone task
for human beings. It would be convenient if we could automate this process to
get it right every time. For this reason, computer scientists have developed
another program, called a loader, to perform this task. A loader takes a set of
machine language instructions as input and loads them into the appropriate
memory locations. When the loader is finished, the machine language program is
ready to execute. Obviously, the loader cannot load itself into memory, so this is
one of those algorithms that must be hardwired into the computer.
Now that a loader exists, we can load and execute other programs that make
the development, execution, and management of programs easier. This type of
software is called system software. The most important example of system soft-
ware is a computer’s operating system. You are probably already familiar with at
least one of the most popular operating systems, such as Linux, Apple’s Mac OS,

[8] CHAPTER 1 Introduction

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
and Microsoft Windows. An operating system is responsible for managing and
scheduling several concurrently running programs. It also manages the com-
puter’s memory, including the external storage, and manages communications
between the CPU, the input/output devices, and other computers on a network.
An important part of any operating system is its file system, which allows human
users to organize their data and programs in permanent storage. Another impor-
tant function of an operating system is to provide user interfaces—that is, ways
for the human user to interact with the computer’s software. A terminal-based
interface accepts inputs from a keyboard and displays text output on a monitor
screen. A modern graphical user interface (GUI) organizes the monitor screen
around the metaphor of a desktop, with windows containing icons for folders,
files, and applications. This type of user interface also allows the user to manipu-
late images with a pointing device such as a mouse.
Another major type of software is called applications software, or simply
applications. An application is a program that is designed for a specific task, such
as editing a document or displaying a Web page. Applications include Web
browsers, word processors, spreadsheets, database managers, graphic design pack-
ages, music production systems, and games, among many others. As you begin to
learn to write computer programs, you will focus on writing simple applications.
As you have learned, computer hardware can execute only instructions that
are written in binary form—that is, in machine language. Writing a machine lan-
guage program, however, would be an extremely tedious, error-prone task. To
ease the process of writing computer programs, computer scientists have devel-
oped high-level programming languages for expressing algorithms. These lan-
guages resemble English and allow the author to express algorithms in a form
that other people can understand.
A programmer typically starts by writing high-level language statements in a
text editor. The programmer then runs another program called a translator to
convert the high-level program code into executable code. Because it is possible
for a programmer to make grammatical mistakes even when writing high-level
code, the translator checks for syntax errors before it completes the translation
process. If it detects any of these errors, the translator alerts the programmer via
error messages. The programmer then has to revise the program. If the transla-
tion process succeeds without a syntax error, the program can be executed by the
run-time system. The run-time system might execute the program directly on
the hardware or run yet another program called an interpreter or virtual
machine to execute the program. Figure 1.3 shows the steps and software used in
the coding process.

1.2 The Structure of a Modern Computer System [9]

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Syntax error messages
Text editor Translator

Create high-level
language program

Run-time Other error messages


User inputs system

Program
outputs

[FIGURE 1.3] Software used in the coding process

1.2 Exercises
1 List two examples of input devices and two examples of output devices.
2 What does the central processing unit (CPU) do?
3 How is information represented in hardware memory?
4 What is the difference between a terminal-based interface and a graphical
user interface?
5 What role do translators play in the programming process?

1.3 A Not-So-Brief History of Computing


Systems
Now that we have in mind some of the basic ideas of computing and computer
systems, let’s take a moment to examine how they have taken shape in history.
Figure 1.4 summarizes some of the major developments in the history of comput-
ing. The discussion that follows provides more details about these developments.

[ 10 ] CHAPTER 1 Introduction

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exploring the Variety of Random
Documents with Different Content
MÉMOIRES D'OUTRE-TOMBE. 333 tissements, nos fêtes et
surtout notre jeunesse? Des mères de famille, des jeunes filles qui
commençaient la vie par l'adversité, apportaient le fruit semainier du
labeur, pour s'éjouir à quelque danse de la patrie. Des attachements
se formaient dans les causeries du soir après le travail, sur les
gazons d'Amstead et de Primrose-Hill. A des chapelles, ornées de
nos mains dans de vieilles masures, nous priions le 21 janvier et le
jour de la mort de la reine, tout émus d'une oraison funèbre
prononcée par le curé émigré de notre village. Nous allions le long
de la Tamise, tantôt voir surgir aux docks les vaisseaux chargés des
richesses du monde, tantôt admirer les maisons de campagne de
Richmond, nous si pauvres, nous privés du toit paternel : toutes ces
choses sont de véritables félicités ! Quand je rentre en 1822, au lieu
d'être reçu par mon ami, tremblotant de froid, qui m'ouvre la porte
de notre grenier en me tutoyant, qui se couche sur son grabat
auprès du mien, en se recouvrant de son mince habit et ayant pour
lampe le clair de lune, —je passe h la lueur des flambeaux entre
deux files de laquais, c{ui vont aboutir à cinq ou six respectueux
secrétaires. J'arrive, tout criblé sur ma route des mots :
Monseifjneur, Mylord, Votre Excellence^ Monsieur l'Ambassadeur, à
un salon tapissé d'or et de soie. — Je vous en supplie, messieurs,
laissez-moi ! Trêve de ces Mylords! Que voulez-vous que je fasse de
vous? Allez rire à la chancellerie, comme si je n'étais i»as là.
Prétendez-vous me faire prendre au sérieux cette mascarade?
Pensez-vous que je sois assez bête pour me croire changé de nature
parce que j'ai changé d'habit? Le
336 MÉMOIRES D'OUTRE-TOMBE. marquis de Londonderry
va venir, dites-vous; le duc de Wellington m'a demandé; M. Canning
me cherche; lady Jersey m'attend à dîner avec M. Brougham; lady
Gwidir m'espère, à dix heures, dans sa loge à l'Opéra; lady
Mansfield, à minuit, à Almacks. Miséricorde ! où me fourrer? qui me
délivrera? qui m'arrachera à ces persécutions? Revenez, beaux jours
de ma misère et de ma solitude! Ressuscitez, compagnons de mon
exil l Allons, mes vieux camarades du lit de camp et de la couche de
paille, allons dans la campagne, dans le petit jardin d'une taverne
dédaignée, boire sur un banc de bois une tasse de mauvais thé, en
parlant de nos folles espérances et de notre ingrate patrie, en
devisant de nos chagrins, en cherchant le moyen de nous assister
les uns les autres, de secourir un de nos parents encore plus
nécessiteux que nous. Voilà ce que j'éprouve, ce que je me dis dans
ces premiers jours de mon ambassade à Londres. Je n'échappe à la
tristesse qui m'assiège sous mon toit qu'en me saturant d'une
tristesse moins pesante dans le parc de Kensington. Lui, ce parc,
n'est point changé; les arbres seulement ont grandi; toujours
solitaire, les oiseaux y font leur nid en paix. Ce n'est plus même la
mode de se rassembler dans ce lieu , comme au temps que la plus
belle des Françaises, madame Récamier, y passait suivie de la foule.
Du bord des pelouses désertes de Kensington, j'aime à voir courre, à
travers Hyde-Park, les troupes de chevaux, les voitures des
fashionables, parmi lesquelles figure mon tilbury vide, tandis que,
redevenu gentillàtre émigré, je remonte l'allée où le confesseur
banni disait autrefois son bréviaire.
MÉMOIRES D'OUTRE-TOMBE.- 337 C'est dans ce parc de
Kensington que j'ai médité l'Essai historique; que, relisant le journal
de mes courses d'outre-mer, j'en ai tiré les amours cVAtala; c'est
aussi dans ce parc, après avoir erré au loin dans les campagnes sous
un ciel baissé, blondissant et comme pénétré de la clarté polaire,
que je traçai au crayon les premières ébauches des passions de
René. Je déposais, la nuit, la moisson de mes rêveries du jour dans
V Essai historique et dans les Nalchez. Los deux manuscrits
marchaient de front, bien que souvent je manquasse d'argent pour
en acheter le papier, et que j'en assemblasse les feuillets avec des
pointes arrachées aux tasseaux de mon grenier, faute de 111. Ces
lieux de mes premières inspirations me font sentir leur puissance ; ils
reflètent sur le présent la douce lumière des souvenirs : je me sens
en train de reprendre la plume. Tant d'heures sont perdues dans les
ambassades! Le temps ne me faut pas plus ici qu'à Berlin pour
continuer mes Mémoires, édifice que je bâtis avec des ossements et
des ruines. Mes secrétaires à Londres désirent aller le matin à des
pique-niques et le soir au bal : très-volontiers! Les gens. Peter,
Valeniin, Lewis, vont à leur tour au cabaret, et les femmes, Rose,
Peggy, Maria, à la promenade des trottoirs; j'en suis charmé. On me
laisse la clef de la porte extérieure : monsieur l'ambassadeur est
commis à la garde de sa maison ; si on frappe, il ouvrira. Tout le
monde est sorti; me voilà seul : mettons-nous à l'œuvre. Il y a vingt-
deux ans, je viens de le dire, que j'esquissais à Londres les Nalchez
et Atala; j'en suis précisément dans mes Mémoires à l'époque de
mes voyages en 1. ti
338 MÉMOIRES D'OUTRE-TOMBE. Amérique : cela se
rejoint à merveille. Supprimons ces vingt-deux ans, comme ils sont
en effet supprimés de ma vie, et partons pour les forêts du Nouveau
Monde : le récit de mon ambassade viendra à sa date, quand il
plaira à Dieu; mais, pour peu que je reste ici quelques mois, j'aurai
le loisir d'arriver de la cataracte de Niagara à l'armée des princes en
Allemagne, et de l'armée des princes à ma retraite en Angleterre.
L'ambassadeur du roi de France peut raconter l'histoire de l'émigré
français dans le lieu même où celui-ci était exilé.
Londres, d'avril à septembre 1S2'2. TRAVERSEE DE L
OCEAN. Le livre précédent se termine par mon embarquement à
Saint-Malo. Bientôt nous sortîmes de la Manche, et l'immense houle
de l'ouest nous annonça l'Atlantique. Il est difficile aux personnes qui
n'ont jamais navigué de se faire une idée des sentiments qu'on
éprouve lorsque du bord d'un vaisseau on n'aperçoit de toutes parts
que la face sérieuse de l'abime. Il y a dans la vie périlleuse du marin
une indépendance qui tient de l'absence'de la terre; on laisse sur le
rivage les passions des hommes; entre le monde que l'on quitte et
celui que l'on cherche, on n'a pour amour et pour patrie que
l'élément sur lequel on est porté : plus de devoirs à remjtlir, plus de
visites à rendre, plus de journaux, plus de politique. La langue même
des matelots n'est pas la langue ordinaire : c'est une langue telle
que la parlent l'Océan
340 MÉMOIRES D'OUTRE-TOMBE. et le ciel, le calme et la
tempête. Vous habitez un univers d'eau parmi des créatures dont le
vêtement, les goûts, les manières, le visage, ne ressemblent point
aux peuples autochthones : elles ont la rudesse du loup marin et la
légèreté de l'oiseau; on ne voit point sur leur front les soucis de la
société ; les rides qui le traversent ressemblent aux plissures de la
voile diminuée, et sont moins creusées par l'âge que par la bise,
ainsi que dans les flots. La peau de ces créatures, imprégnée de sel,
est rouge et rigide, comme la surfaoe de l'écueil battu de la lame.
Les matelots se passionnent pour leur navire; ils pleurent de regret
en le quittant, de tendresse en le retrouvant. Ils ne peuvent rester
dans leur famille; après avoir juré cent fois qu'ils ne s'exposeront
plus à la mer, il leur est impossible de s'en passer, comme un jeune
homme ne se peut arracher des bras d'une maîtresse orageuse et
infidèle. Dans les docks de Londres et de Plymouth, il n'est pas rare
de trouver des sailors nés sur des vaisseaux : depuis leur enfance
jusqu'à leur vieillesse, ils ne sont jamais descendus au rivage; ils
n'ont vu la terre que du bord de leur berceau flottant, spectateurs du
monde où ils ne sont point entrés. Dans cette vie réduite à un si
petit espace, sous les nuages et sur les abimes, tout s'anime pour le
marinier : une ancre, une voile, un mât, un canon, sont des
personnages qu'on afî'ectionne et qui ont chacun leur histoire. La
voile fut déchirée sur la côte du Labrador; le maître voilier lui mit la
pièce que vous voyez. L'ancre sauva le vaisseau quand il eut chassé
MEMOIR[-S D'OUTRE-TOMBE. 341 sur SOS autres aucres,
au milieu des coraux des îles Sandwich. Le mât fut rompu dans une
bourrasque au cap de Bonne-Espérance; il n'était que d'un seul jet; il
est beaucoup plus fort depuis qu'il est composé de deiu pièces. Le
canon est le seul qui ne fut pas démonté au combat de la
Chesapeake. Les nouvelles du bord sont des plus intéressantes : on
vient de jeter le loch; le navire file dix nœuds. Le ciel est clair à midi
; on a pris hauteur : on est à telle latitude. On a fait le point : il y a
tant de lieues gagnées en bonne route. La déclinaison de l'aiguillp.
est de tant de degrés : on s'est élevé au nord. Le sable des sabliers
passe mal : on aura de la pluie. On a remarqué des procellana dans
le sillage du vaisseau : on essuiera un grain. Des poissons volants se
sonf montrés au sud : le temps va se calmer. Une éclaircie s'est
formée à l'ouest dans les nuages : c'est le pied du vent; demain, le
vent soufflera de ce côté. L'eau a changé de couleur; on a vu flotter
du bois et des goémons; on a aperçu des mouettes et des canards;
un petit oiseau est venu se percher sur les vergues : il faut mettre le
cap dehors, car on approche de terre, et il n'est pas bon de
l'accoster la nuit. Dans l'épinette, il y a un coq favori et pour ainsi
342 MÉMOIRES D'OUTRE-TOMBE. dire sacré, qui survit à
tous les autres; il est fameux pour avoir chanté pendant un combat,
comme dans la cour d'une ferme au milieu de ses poules. Sous les
ponts habite un chat : peau verdâtre zébrée, queue pelée,
moustaches de crin, ferme sur ses pattes, opposant le contre-poids
au tangage et le balancier au roulis; il a fait deux fois le tour du
monde, et s'est sauvé d'un naufrage sur un tonneau. Les mousses
donnent au coq du biscuit trempé dans du vin, et Matou a le
privilège de dormir, quand il lui plait, dans le vitchoura du second
capitaine. Le vieux matelot ressemble au vieux laboureur. Leurs
moissons sont différentes, il est vrai : le matelot a mené une vie
errante, le laboureur n'a jamais quitté son champ; mais ils
connaissent également les étoiles et prédisent l'avenir en creusant
leurs sillons. A l'un, l'alouette, le rouge-gorge, le rossignol; à l'autre,
la procellaria, le courlis, l'alcyon, — leurs prophètes. Ils se retirent le
soir, celui-ci dans sa cabine, celui-là dans sa chaumière; frêles
demeures, où l'ouragan qui les ébranle n'agite point des consciences
tranquilles. If the wind tempestuous is blowing, Still no danger they
descry ; The guiUless heart its boon bestowing, Soothes them with
its LuUaby, etc., etc. « Si le vent souffle orageux, ils n'aperçoivent
aucun « danger; le cœur innocent, versant son baume, les « berce
avec ses dodo„ l'enfant do; dodo, l'enfant do, etc. » Le matelot ne
sait où la mort le surprendra, à quel bord il laissera sa vie : peut-
être, quand il aura mêlé au
MÉMOIRES D'OUTRE-TOMBE. 343 vsnt son dernier soupir,
sera-t-il lancé au sein des flots, attaché sur deux avirons, pour
continuer son voyage; peut-être sera-t-il enterré dans un îlot désert
que l'on ne retrouvera jamais, ainsi qu'il a dormi isolé dans son
hamac, au milieu de l'Océan. Le vaisseau seul est un spectacle :
sensible au plus léger mouvement du gouvernail. Hippogriffe ou
coursier ailé, il obéit à la main du pilote, comme un cheval à la main
d'un cavalier. L'élégance des mâts et des cordages, la légèreté des
matelots qui voltigent sur les vergues, les différents aspects dans
lescpels se présente le navire, soit qu'il vogue penché par un autan
contraire, soit qu'il fuie droit devant un aquilon favorable, font de
cette machine savante une des merveilles du génie de l'homme.
Tantôt la lame et son écume brisent et rejaillissent contre la carène;
tantôt l'onde paisible se divise, sans résistance, devant la proue. Les
pavillons, les flammes, les voiles achèvent la beauté de ce palais de
Neptune : les plus basses voiles , déployées dans leur largeur,
s'arrondissent comme de vastes cylindres; les plus hautes,
comprimées dans leur milieu, ressemblent aux mamelles d'une
sirène. Animé d'un soufile impétueux, le navire, avec sa quille,
comme avec le soc d'une charrue, laboure à grand bruit le champ
des mers. Sur ce chemin de l'Océan, le long duquel on n'aperçoit ni
arbres, ni villages, ni villes, ni tours, ni clochers, ni tombeaux ; sur
cette route sans colonnes, sans pierres milliaires, qui n'a pour bornes
que les vagues, pour relais que les vents, pour flambeaux que les
astres, la plus belle des aventures, quand on n'est pas en quête de
terres et de mers inconnues, est la rencontre de deux
3i4 MÉMOIRES D'OUTRE-TOMBE. vaisseaux. On se
découvre mutuellement à l'horizon avec la longue-vue; on se dirige
les uns vers les autres. Les équipages et les passagers s'empressent
sur le pont. Les deux bâtiments s'approchent, hissent leur pavillon,
carguent à demi leurs voiles, se mettent en travers. Quand tout est
silence, les deux capitaines, placés sur le gaillard d'arrière, se hèlent
avec le porte-voix : « Le nom du navire? De quel port? Le nom du
capitaine? D'où vient-il? Combien de jours de traversée? La latitude
et la longitude? Adieu, va! » On lâche les ris; la voile retombe. Les
matelots et les passagers des deux vaisseaux se regardent fuir, sans
mot dire : les uns vont chercher le soleil de l'Asie, les autres le soleil
de l'Europe, qui les verront également mourir. Le temps emporte et
sépare les voyageurs sur la terre, plus promptement encore que le
vent ne les emporte et ne les sépare sur l'Océan; on se fait un signe
de loin : Adieu, val Le port commun est l'Éternité. Et si le vaisseau
rencontré était celui de Cook ou de La Pérouse? Le maître de
l'équipage de mon vaisseau malouin était un ancien subrécargue,
appelé Pierre Villeneuve, dont le nom seul me plaisait à cause de la
bonne Villeneuve. Il avait servi dans l'Inde sous le bailli de Suffren,
et en Amérique sous le comte d'Eslaing; il s'était trouvé à une
multitude d'affaires. Appuyé sur l'avant du vaisseau, auprès du
beaupré, de même qu'un vétéran assis sous la treille de son petit
jardin dans le fossé des Invalides, Pierre, en mâchant une chicpie de
tabac, qui lui enflait la joue comme une fluxion, me peignait le
moment du branle-bas, l'effet des détona 
MÉMOIRES D'OUTRE-TOMBE. 345 tions de l'artillerie sous
les pouts^ le ravage des boulets dans leurs ricochets contre les
affûts, les canons, les pièces de charpente. Je le faisais parler des
Indiens, des nègres, des colons. Je lui demandais comment étaient
habillés les peuples, comment les arbres faits, quelle couleur avaient
la terre et le ciel, quel goût les fruits; si les ananas étaient meilleurs
que les pêches, les palmiers plus beaux que les chênes. Il
m'expliquait tout cela par des comparaisons prises des choses que je
connaissais : le palmier était un grand chou, la robe d'un Indien celle
de ma graud'mère; les chameaux ressemblaient à un âne bossu ;
tous les peuples de l' Orient, et notamment les Chinois, étaient des
poltrons et des voleurs. Villeneuve était de Bretagne, et nous ne
manquions pas de finir par l'éloge de l'incomparable beauté de notre
patrie. La cloche interrompait nos conversations; elle réglait les
quarts, l'heure de l'habillement, celle de la revue, celle des repas. Le
matin, à un signal, l'équipage, rangé sur le pont, dépouillait la
chemise bleue pour en revêtir une autre qui séchait dans les
haubans. La chemise quittée était immédiatement lavée dans des
baquets, où cette pension de phoques savonnait aussi des faces
brunes et des pattes goudronnées. Au repas du midi et du soir, les
matelots, assis en rond autour des gamelles, plongeaient l'un après
l'autre, régulièrement et sans fraude, leur cuiller d'étain dans la
soupe flottante au roulis. Ceux qui n'avaient pas faim vendaient,
pour un morceau de tabac ou pour un verre d'eau-de-vie, leur
portion de biscuit et de viande salée à leurs camarades. Les
passagers mangeaient dans la
346 xMÉMOIRES D'OUTRE-TOMBE. chambre du capitaine.
Quand il faisait beau, on tendait une voile sur l'arrière du vaisseau,
et l'on dînait à la vue d'une mer bleue, tachetée çà et là de marques
blanches par les écorchures de la brise. Enveloppé de mon manteau,
je me couchais la nuit sur le tillac. Mes regards contemplaient les
étoiles audessus de ma tête. La voile enflée me renvoyait la
fraîcheur de la brise qui me berçait sous le dôme céleste : à demi
assoupi et poussé par le vent, je changeais de ciel en changeant de
rêve. Les passagers, à bord d'un vaisseau, offrent une société
différente de celle de l'équipage : ils appartiennent à un autre
élément; leurs destinées sont de la terre. Les uns courent chercher
la fortune, les autres le repos; ceux-là retournent à leur patrie, ceux-
ci la quittent; d'autres naviguent pour s'instruire des mœurs des
peuples, pour étudier les sciences et les arts. On a le loisir de se
connaître dans cette hôtellerie errante qui voyage avec le voyageur,
d'apprendre maintes aventures, de concevoir des antipathies, de
contracter des amitiés. Quand vont et viennent ces jeunes femmes
nées du sang anglais et du sang indien, qui joignent à la beauté de
Clarisse la délicatesse de Sacontala, alors se forment des chaînes
que nouent et dénouent les vents parfumés de Ceylan, douces
comme eux, comme eux légères.
Londres, d'avril à septembre 1822. FRANCIS TULLOCII.
CURISTOPHE COLOMB. — CAMOENS. Parmi les passagers, mes
compagnons, se trouvait un Anglais. Francis Tulloch avait servi dans
l'artillerie: peintre, musicien, mathématicien, il parlait plusieurs
langues. L'abbé ]\agault, supérieur des Sulpiciens, ayant rencontré
l'ofïicier anglican, en fit un catholique : il emmenait son néophyte à
Baltimore. Je m'accointai avec Tulloch : comme j'étais alors profond
philosophe, je l'invitais à revenir chez ses parents. Le spectacle que
nous avions sous les yeux le transportait d'admiration. ISous notis
levions la nuit, lorsque le pont était abandonné à l'officier de quart et
à quelques matelots qui fumaient leur pipe en silence : Tuta œquora
silent. Le vaisseau roulait au gré des lames sourdes et lentes, tandis
que des étincelles de feu couraient avec une blanche écume le long
de ses flancs. Des milliers d'étoiles
348 MÉMOIRES D'OUTRE-TOMBE. rayonnant dans le
sombre azur du dôme céleste, une mei sans rivage, l'infini dans le
ciel et sur les flots! Jamais Dieu ne m'a plus troublé de sa grandeur
que dans ces nuits où j'avais l'immensité sur ma tôte et l'immensité
sous mes pieds. Des vents d'ouest, entremêlés de calmes,
retardèrent jotre marche. Le 4 mai nous n'étions qu'à la hauteur des
Açores. Le 6, vers les huit heures du matin, nous eûmes
connaissance de l'île du Pic; ce volcan domina longtemps des mers
non naviguées : inutile phare la nuit, signal sans témoin le jour. Il y
a quelque chose de magique à voir s'élever la terre du fond de la
mer. Christophe Colomb, au milieu d'un équipage révolté, prêt à
retourner en Europe sans avoir atteint le but de son voyage, aperçoit
une petite lumière sur une plage que la nuit lui cachait. Le vol des
oiseaux l'avait guidé vers l'Amérique; la lueur du foyer d'un sauvage
lui révèle un nouvel univers. Colomb dut éprouver cette sorte de
sentiment que l'Écriture donne au Créateur rpiand, après avoir tiré le
monde du néant, il vit que son ouvrage était bon : vidît Deus quod
esset bonum. Colomb créait un monde. Une des premières vies du
pilote génois est celle que Giustiniani, publiant un psautier hébreu,
plaça en forme de îiote sous le psaume : Cœli enarrant gloriam Deu
Yasco de Gama ne dut pas être moins émerveillé lorsqu'en 1498 il
aborda la côte de Malabar. Alors, tout change sur le globe : une
nature nouvelle apparaît ; le rideau qui depuis des milliers de siècles
cachait une partie de la terre se lève : on découvre la patrie du
soleil, le lieu d'où il sort chaque matin « comme un
MEMOIRES D'OUTRE-TOMBE. 349 « époux, OU comme un
géant, tanquam sponsus, ut gigas; » on voit à nu ce sage et brillant
Orient, dont l'histoire mystérieuse se mêlait aux voyages de
Pythagore, aux conquêtes d'Alexandre, au souvenir des croisades, et
dont les parfums nous arrivaient à travers les champs de l'Arabie et
les mers de la Grèce. L'Europe lui envoya un poëte pour le saluer : le
cygne du Tage fit entendre sa triste et belle voix sur les rivages de
l'Inde; Camoëns leur emprunta leur éclat, leur renommée et leur
malheur; il ne leur laissa que leurs richesses.
LES ACORES. — ILE GRACIOSA. Lorsque Gonzalo Villo,
aïeul maternel de Camoëns, découvrit une partie de l'archipel des
Açores, il aurait dû, s'il eût prévu l'avenir, se réserver une concession
de six pieds de terre pour recouvrir les os de son petit-fils. Nous
ancrâmes dans une mauvaise rade, sur une base de roches, par
quarante-cinq brasses d'eau. L'ile Graciosa, devant laquelle nous
étions mouillés, nous présentait ses collines un peu renflées dans
leurs contours comme les ellipses d'une amphore étrusque : elles
étaient drapées de la verdure des blés, et elles exhalaient une odeur
fromentacée agréable, particulière aux moissons des Açores. On
voyait au milieu de ces tapis les divisions des champs, formées de
pierres volcaniques, mi-parties blanches et noires, et entassées les
unes sur les autres. Une ahbaye, monument d'un ancien monde sur
un sol nouveau, se montrait au sommet d'un tertre ; au pied de
332 MI^MOIRES D'OUTRE-TOMBE. ce tertre, dans une
anse caillouteuse, miroitaient les toits rouges de la ville de Santa-
Cruz. L'île entière, avec ses découpures de baies, de caps, de
criques, de promontoires, répétait son paysage inverti dans les flots.
Des rochers verticaux au plan des vagues lui servaient de ceinture
extérieure. Au fond du tableau, le cône du volcan du Pic, planté sur
une coupole de nuages, perçait, par delà Graciosa, la perspective
aérienne. Il fut décidé que j'irais à terre avec Tulloch et le second
capitaine; on mit la chaloupe en mer : elle nagea au rivage dont
nous étions à environ deux milles. Nous aperçûmes du mouvement
sur la côte ; une prame s'avança vers nous. Aussitôt qu'elle fut à
portée de la voix, nous distinguâmes une quantité de moines. Ils
nous hélèrent en portugais, en italien, en anglais, en français, et
nous répondîmes dans ces quatre langues. L'alarme régnait, notre
vaisseau était le premier bâtiment d'un grand port qui eût osé
mouiller dans la rade dangereuse où nous étalions la marée. D'une
autre part, les insulaires voyaient pour la première fois le pavillon
tricolore ; ils ne savaient si nous sortions d'Alger ou de Tunis :
Neptune n'avait point reconnu ce pavillon si glorieusement porté par
Cybèle. Quand on vit que nous avions figure humaine et que nous
entendions ce qu'on disait, la joie fut extrême. Les moines nous
recueillirent dans le bateau, et nous ramâmes gaiement vers
SantaCruz : nous y débarquâmes avec quelque diflîculté, à cause
d'un ressac assez violent. Toute l'île accourut. Quatre ou cinq
alguazils. armés de piques rouillées, s'emparèrent de nous.
L'uniforme de Sa Majesté m' attirant les honneurs, je passai pour
MÉMOIRES D'OUTRE-TOMBE. 353 l'homme important de la
dénutation. Oti nous conduisit chez le gouverneur, dans un taudis,
où Son Excellence, vêtue d'un méchant habit vert, autrefois galonné
d'or, TOUS donna une audience solennelle : il nous permit le
ravitaillement. Nos religieux nous menèrent à leur couvent, édifice à
balcons commode et bien éclairé. Tulloch avait trouvé un
compatriote : le principal frère, qui se donnait tous les mouvements
pour nous, était un matelot de Jersey, dont le vaisseau avait péri
corps et biens sur Graciosa. Sauvé seul du naufrage, ne manquant
pas d'intelligence, il se montra docile aux leçons des catéchistes ; il
apprit le portugais et quelques mots de latin; sa qualité d'Anglais
militant en sa faveur, on le convertit et on en fit un moine. Le
matelot jerseyais, logé, vêtu et nourri à l'autel , trouvait cela
beaucoup plus doux que d'aller serrer la voile du perroquet de
fougue. Il se souvenait encore de son ancien métier : ayant été
longtemps sans parler sa langue, il était enchanté de rencontrer
quelqu'un qui l'entendît; il riait et jurait en vrai pilotin. Il nous
promena dans l'île. Les maisons des villages, bâties en planches et
en pierres, s'enjolivaient de galeries extérieures qui donnaient un air
propre à ces cabanes, parce qu'il y régnait beaucoup de lumière. Les
paysans, presque tous vignerons, étaient à moitié nus et bronzés par
le soleil; les femmes, petites, jaunes comme des mulâtresses, mais
éveillées, étaient naïvement coquettes avec leurs bouquets de
seringas, leurs chapelets en guise de couronnes ou de chaînes. Les
pentes des collines rayonnaient de ceps, dont 1. 2à
354 MÉMOIRES D'OUTRE-TOMBE. ie vin approchait celui de
ïayai. L'eau était rare, mais, partout où sourdait une lontaine,
croissait un figuier et s'élevait un oratoire avec un portique peint à
fresque. Les ogives du portique encadraient quelques aspects de l'île
et quelques portions de la mer. C'est sur un de ces figuiers que je vis
s'abattre une compagnie de sarcelles bleues, non palmipèdes.
L'arbre n'avait point de feuilles, mais il portait des fruits rouges
enchâssés comme des cristaux. Quand il fut orné des oiseaux
cérulés qui laissaient pendre leurs ailes, ses fruits parurent d'une
pourpre éclatante, tandis que l'arbre semblait avoir poussé tout à
coup un feuillage d'azur. Il est probable que les Açores furent
connues des Carthaginois; il est certain que des monnaies
phéniciennes ont été déterrées dans l'Ile de Corvo. Les navigateurs
modernes qui abordèrent les premiers à cette île trouvèrent, djt-on,
une statue équestre, le bras droit étendu et montrant du doigt
l'Occident, si toutefois cette statue n'est pas la gravure d'invention
qui décore les anciens portulans. J'ai supposé, dans le manuscrit des
Natclwz, que Chactas, revenant d'Europe, prit terre à l'ile de Corvo,
et qu'il rencontra la statue mystérieuse. Il exprime ainsi les
sentiments qui m'occupaient à Graciosa, en me rappelant la tradition
: « J'approche de ce monument extraor« dinaire. Sur sa base,
baignée de l'écume des flots, « étaient gravés des caractères
inconnus : la mousse et « le salpêtre des mers rongeaient la surface
du bronze « antique; l'alcyon, perché sur le casque du colosse, « y
jetait, par intervalles, des voix langoureuses; des « coquillages se
collaient aux lianes et aux crins d'airain
MÉMOIRES D'OUTRE-TOMBE. 335 « du coursier, et
lorsqu'on approchait l'oreille de ses « naseaux ouverts, on croyait
ouïr des rumeurs con« fuses. » Un bon souper nous fut servi chez
les religieux après notre course ; nous passâmes la nuit à boire avec
nos hôtes. Le lendemain, vers midi, nos provisions embarquées,
nous retournâmes à bord. Les religieux se chargèrent de nos lettres
pour l'Europe. Le vaisseau s'était trouvé en danger par la levée d'un
fort sud-est. On vira l'ancre; mais, engagée dans des roches, on la
perdit, comme on s'y attendait. Nous appareillâmes : le vent
continuant de fraîchir, nous eûmes bientôt dépassé les Açores,
Londres, d'avril à septembre IT. JEUX MARINS. — ILE
SAINT -PTETÎRE. Fac pelagus me scire probes, quo carbasa laxo. «
Muse, aide-moi à montrer que je connais la mer « sur laquelle je
déploie mes voiles. » C'est ce que disait, il y a six cents ans,
Guillaume le Breton, mon compatriote. Rendu à la mer, je
recommençai à contempler ses solitudes; mais à travers le monde
idéal de mes rêveries m'apparaissaient, moniteurs sévères, la France
et les événements réels. Ma retraite pendant le jour, lorsque je
voulais éviter les passagers, était la hune du grand mât; j'y montais
lestement aux applaudissements des matelots. Je m'y asseyais
dominant les vagues. L'espace tendu d'un double azur avait l'air
d'une toile préparée pour recevoir les futures créations d'un grand
peintre. La couleur des eaux était pareille à celle du verre li(|uide.
De longues et hautes ondulations
3o8 MÉMOIRES D'OUTRE-TOMBE. ouvraient dans leurs
ravines des échappées de vue sur les déserts de l'Océan : ces
vacillants paysages rendaient sensible à mes yeux la comparaison
que fait l'Écriture de la terre chancelante devant le Seigneur, comme
un homme ivre. Quelquefois, on eut dit l'espace étroit et borné,
faute d'un point de saillie; mais si une vague venait à lever la tête,
un flot à se courber en imitation d'une côte lointaine, un escadron de
chiens de mer à passer à l'horizon, alors se présentait une échelle de
mesure. L'étendue se révélait, surtout lorsqu'une brume, rampant à
la surface pélagienne, semblait accroître l'immensité même.
Descendu de l'aire du mât comme ar^refois du nid de mon saule,
toujours réduit à une existence solitaire, je soupais d'un biscuit de
vaisseau, d'un peu de sucre et d'un citron; ensuite je me couchais,
ou sur le tillac dans mon manteau, ou sous le pont dans mon cadre :
je n'avais qu'à déployer mou bras pour atteindre de mon lit à mon
cercueil. Le vent nous força d'anordir et nous accostâmes le banc de
Terre-Neuve. Quelques glaces, flottantes rôdaient au milieu d'une
bruine froide et pâle. Les hommes du trident ont des jeux qui leur
viennent de leurs devanciers : quand on passe la Ligne, il faut se
résoudre à recevoir le baptême : même cérémonie sous le Tropique,
même cérémonie sur le banc de TerreNeuve, et, quel que soit le lieu,
le chef de la mascarade est toujours le bonhomme Tropique.
Tropique et hydropique sont synoDymes pour les matelots : le
bonhomme Tropique a donc une bedaine énorme; il est vêtu, lors
même qu'il est sous son tropique, de toutes les peaux
I MÉMOIRES D'OUTRE-TOMBE. 359 de mouton et de toutes
les jaquettes fourrées de l'équipage. Il se tient accroupi dans la
grande hune, poussant de temps en temps des mugissements.
Chacun le regarde d'en bas : il commence à descendre le long des
haubans, pesant comme un ours, trébuchant comme Silène. En
mettant le pied sur le pont, il pousse de nouveaux rugissements,
bondit, saisit un seau, le remplit d'eau de mer et le verse sur le chef
de ceux qui n'ont pas passé la Ligne, ou qui ne sont pas parvenus à
la latitude des glaces. On fuit sous les ponts, on remonte sur les
écoutilles, on grimpe aux mâts : père Tropique vous poursuit; cela
finit au moyen d'un large pourboire : jeux d'Amphitrite, cpi' Homère
aurait célébrés comme il a chanté Protée, si le vieil Océanus eût été
connu tout entier du temps d'Ulysse; mais alors on ne voyait encore
que sa tête aux Colonnes d'Hercule; son corps caché couvrait le
monde. Nous gouvernâmes vers les îles Saint- Pierre et Miquelon,
cherchant une nouvelle relâche. Quand nous approchâmes de la
première, un matin, entre dix heures et midi, nous étions presque
dessus; ses côtes perçaient, en forme de bosse noire, à travers la
brume. Nous mouillâmes devant la capitale de l'île : nous ne la
voyions pas, mais nous entendions le bruit de la terre. Les passagers
se hâtèrent de débarquer ; le supérieur de Saint-Sulpice,
continuellement harcelé du mal de mer, était si faible, qu'on fut
obligé de le porter au rivage. Je pris un logement à part; j'attendis
qu'une rafale, arrachant le brouillard, me montrât le lieu que
j'habitais, et pour ainsi dire le visage de mes hôtes dans ce pays des
ombres.
360 MÉMOIRES D'OUTRE-TOMBE. Le port et la rade de
Saint-Pierre sont placés entre la côte orientale de l'Ile et un îlot
allongé, Y île aux Chiens, Le port, surnommé le Barachois, creuse les
terres et aboutit à une flaque saumâtre. Des mornes stériles se
serrent au noyau de l'ile : quelques-uns, détachés, surplombent le
littoral ; les autres ont à leur pied une lisière de landes tourbeuses et
arasées. On aperçoit du bourg le morne de la vigie. La maison du
gouverneur fait face à l'embarcadère. L'église, la cure, le magasin
aux vivres, sont placés au même lieu; puis viennent la demeure du
commissaire de la marine et celle du capitaine du port. Ensuite
commence, le long du rivage sur les galets, la seule rue du bourg. Je
dînai deux ou trois fois chez le gouverneur, officier plein d'obligeance
et de politesse. Il cultivait sur un glacis quelques légumes d'Europe.
Après le dîner, il me montrait ce qu'il appelait son jardin. Une odeur
fine et suave d'héliotrope s'exhalait d'un petit carré de fèves en
fleurs; elle ne nous était point apportée par une brise de la patrie,
mais par un vent sauvage de Terre-Neuve, sans relation avec la
plante exilée, sans sympathie de réminiscence et de volupté. Dans
ce parfum non respiré de la beauté, non épuré dans son sein, non
répandu sur ses traces, dans ce parfum changé d'aurore, de culture
et de monde, il y avait toutes les mélancolies des regrets, de
l'absence et de la jeunesse. Du jardin, nous montions aux mornes,
et nous nous arrêtions au pied du mât de pavillon de la vigie. Le
nouveau drapeau français flottait sur notre tête; comme
The text on this page is estimated to be only 12.00%
accurate

LA JiEyj^iE S#^TiL3[E.[^ Garni er frères , Editeurs


Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like