100% found this document useful (1 vote)
264 views

Fundamentals of Python: First Programs, 2nd Edition Kenneth A. Lambert download pdf

Lambert

Uploaded by

corbaburryix
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
264 views

Fundamentals of Python: First Programs, 2nd Edition Kenneth A. Lambert download pdf

Lambert

Uploaded by

corbaburryix
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Fundamentals of Python: First Programs, 2nd


Edition Kenneth A. Lambert

https://textbookfull.com/product/fundamentals-of-python-
first-programs-2nd-edition-kenneth-a-lambert/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Fundamentals Of Python: Data Structures 2nd Edition


Kenneth A. Lambert

https://textbookfull.com/product/fundamentals-of-python-data-
structures-2nd-edition-kenneth-a-lambert/

textboxfull.com

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Building Python Programs 1st Edition Stuart Reges

https://textbookfull.com/product/building-python-programs-1st-edition-
stuart-reges/

textboxfull.com

Fundamentals of Structural Analysis Kenneth M. Leet

https://textbookfull.com/product/fundamentals-of-structural-analysis-
kenneth-m-leet/

textboxfull.com
Head First Python A Brain Friendly Guide 2nd Edition Paul
Barry

https://textbookfull.com/product/head-first-python-a-brain-friendly-
guide-2nd-edition-paul-barry/

textboxfull.com

Fundamentals of Music Processing: Using Python and Jupyter


Notebooks 2nd Edition Meinard Müller

https://textbookfull.com/product/fundamentals-of-music-processing-
using-python-and-jupyter-notebooks-2nd-edition-meinard-muller/

textboxfull.com

Ten Lessons In Introductory Sociology 2nd Edition Kenneth


A. Gould

https://textbookfull.com/product/ten-lessons-in-introductory-
sociology-2nd-edition-kenneth-a-gould/

textboxfull.com

Essentials of Anatomy & Physiology, 2nd Edition Kenneth S.


Saladin

https://textbookfull.com/product/essentials-of-anatomy-physiology-2nd-
edition-kenneth-s-saladin/

textboxfull.com

Learn Python Programming A beginner s guide to learning


the fundamentals of Python language to write efficient
high quality code Romano
https://textbookfull.com/product/learn-python-programming-a-beginner-
s-guide-to-learning-the-fundamentals-of-python-language-to-write-
efficient-high-quality-code-romano/
textboxfull.com
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
second Edition

Fundamentals of Python:
First Programs

Kenneth A. Lambert

Martin Osborne,
Contributing Author

Australia • Brazil • Mexico • Singapore • United Kingdom • United States

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.

Important Notice: Media content referenced within the product description or the product
text may not be available in the eBook version.

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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: © 2019, 2012 Cengage
First Programs, Second Edition
ALL RIGHTS RESERVED. No part of this work covered by the copy-
­Kenneth A. Lambert
right herein may be reproduced or distributed in any form or by
any means, except as permitted by U.S. copyright law, without the
SVP, GM Skills: Jonathan Lau prior written permission of the copyright owner.

Product Team Manager: Kristin Unless otherwise noted all tables/figures exhibits are © 2019 ­Cengage®
McNary

Associate Product Manager: Kate


For product information and technology assistance, contact us
Mason
at Cengage Customer & Sales Support, 1-800-354-9706
Executive Director of Development:
Marah Bellegarde For permission to use material from this text or product, submit
all requests online at www.cengage.com/permissions.
Senior Content Development Further permissions questions can be e-mailed to
­Manager: Leigh Hefferon permissionrequest@cengage.com

Content Development Manager: Jill


Gallagher
Library of Congress Control Number: 2017952738
Senior Content Developer: Natalie
Pashoukos
Softbound ISBN: 978-1-337-56009-2
Product Assistant: Jake Toth Loose Leaf ISBN: 978-1-337-69934-1

Marketing Director: Michele McTighe Cengage


20 Channel Center Street
Marketing Manager: Stephanie Boston, MA, 02210
Albracht
USA
Senior Content Project Manager:
Cengage is a leading provider of customized learning solutions with
Jennifer Feltri-George
employees residing in nearly 40 different countries and sales in more
Senior Designer/Art Director: Diana than 125 countries around the world. Find your local representative
Graham at www.cengage.com.

Cover image: Digital_Art/­ Cengage products are represented in Canada by Nelson Education, Ltd.
Shutterstock.com To learn more about Cengage, visit www.cengage.com.
Production Service/Composition: Purchase any of our products at your local college store or at our
SPi Global ­preferred online store www.cengagebrain.com.

Notice to the Reader

Publisher does not warrant or guarantee any of the products described herein or perform any independent analysis
in connection with any of the product information contained herein. Publisher does not assume, and expressly
disclaims, any obligation to obtain and include information other than that provided to it by the manufacturer. The
reader is expressly warned to consider and adopt all safety precautions that might be indicated by the activities
described herein and to avoid all potential hazards. By following the instructions contained herein, the reader willingly
assumes all risks in connection with such instructions. The publisher makes no representations or warranties of any
kind, including but not limited to, the warranties of fitness for particular purpose or merchantability, nor are any
such representations implied with respect to the material set forth herein, and the publisher takes no responsibility
with respect to such material. The publisher shall not be liable for any special, consequential, or exemplary damages
resulting, in whole or part, from the readers’ use of, or reliance upon, this material.

Printed in the United States of America


Print Number: 01 Print Year: 2017
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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
iii

Pref ace ������������������������������������������������ xiii

CHAPTER 1 I n t ro du ct io n����������������������������������������������� 1
Two Fundamental Ideas of Computer Science: ­
Algorithms and Information Processing ������������������������������ 2
Algorithms ������������������������������������������������������������������� 2
Information Processing��������������������������������������������������� 4
Exercises ������������������������������������������������������������������������ 5
The Structure of a Modern Computer System������������������������ 6
Computer Hardware ������������������������������������������������������� 6
Computer Software ������������������������������������������������������� 7
Exercises ������������������������������������������������������������������������ 9
A Not-So-Brief History of Computing Systems������������������������ 9
Before Electronic Digital Computers��������������������������������11
The First Electronic Digital Computers (1940–1950) ���������13
The First Programming Languages (1950–1965) ��������������14
Integrated Circuits, Interaction,
and Timesharing (1965–1975)��������������������������������������16
Personal Computing and Networks (1975–1990) ��������������17
Consultation, Communication,
and E-Commerce (1990–2000)��������������������������������������19
Mobile Applications and Ubiquitous
Computing (2000–present) ������������������������������������������21
Getting Started with Python Programming ���������������������������22
Running Code in the Interactive Shell ������������������������������22
Input, Processing, and Output�����������������������������������������24
Editing, Saving, and Running a Script ������������������������������27
Behind the Scenes: How Python Works�����������������������������28
Exercises �����������������������������������������������������������������������29
Detecting and Correcting Syntax Errors������������������������������29
Exercises �����������������������������������������������������������������������30
Suggestions for Further Reading ���������������������������������������30
Summary �����������������������������������������������������������������������31

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Review Questions ������������������������������������������������������������32


Projects��������������������������������������������������������������������������33

CHAPTER 2 S o f t w are D
­ evelo pment, Data Ty pes,
iv an d Expres s io n s��������������������������������������� 34
The Software Development Process �����������������������������������35
Exercises �����������������������������������������������������������������������37
Case Study: Income Tax Calculator ������������������������������������38
Strings, Assignment, and Comments�����������������������������������41
Data Types ������������������������������������������������������������������41
String Literals��������������������������������������������������������������42
Escape Sequences��������������������������������������������������������43
String Concatenation�����������������������������������������������������43
Variables and the Assignment Statement��������������������������44
Program Comments and Docstrings ��������������������������������45
Exercises �����������������������������������������������������������������������46
Numeric Data Types and Character Sets �����������������������������47
Integers�����������������������������������������������������������������������47
Floating-Point Numbers��������������������������������������������������47
Character Sets ������������������������������������������������������������48
Exercises �����������������������������������������������������������������������49
Expressions��������������������������������������������������������������������49
Arithmetic Expressions��������������������������������������������������50
Mixed-Mode Arithmetic and Type Conversions��������������������52
Exercises �����������������������������������������������������������������������53
Using Functions and Modules ��������������������������������������������54
Calling Functions: Arguments and Return Values ���������������54
The math Module ���������������������������������������������������������55
The Main Module�����������������������������������������������������������56
Program Format and Structure ���������������������������������������57
Running a Script from a Terminal Command Prompt�����������57
Exercises �����������������������������������������������������������������������59
Summary �����������������������������������������������������������������������59
Review Questions ������������������������������������������������������������61
Projects��������������������������������������������������������������������������62

CHAPTER 3 Lo o ps an d S elec ti on S tatements������������������ 64


Definite Iteration: The for Loop�����������������������������������������65
Executing a Statement a Given Number of Times ��������������65
Count-Controlled Loops��������������������������������������������������66
Augmented Assignment��������������������������������������������������67
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Loop Errors: Off-by-One Error�����������������������������������������68


Traversing the Contents of a Data Sequence ��������������������68
Specifying the Steps in the Range�����������������������������������69
Loops That Count Down ������������������������������������������������69
Exercises �����������������������������������������������������������������������70
Formatting Text for Output������������������������������������������������70 v
Exercises �����������������������������������������������������������������������72
Case Study: An Investment Report��������������������������������������73
Selection: if and if-else Statements ������������������������������77
The Boolean Type, Comparisons, and Boolean
Expressions ���������������������������������������������������������������77
if-else Statements�����������������������������������������������������78
One-Way Selection Statements ���������������������������������������79
Multi-Way if Statements �����������������������������������������������80
Logical Operators and Compound Boolean Expressions �����82
Short-Circuit Evaluation��������������������������������������������������84
Testing Selection Statements �����������������������������������������84
Exercises �����������������������������������������������������������������������85
Conditional Iteration: The while Loop ��������������������������������86
The Structure and Behavior of a while Loop��������������������86
Count Control with a while Loop������������������������������������87
The while True Loop and the break Statement���������������88
Random Numbers ���������������������������������������������������������90
Loop Logic, Errors, and Testing��������������������������������������91
Exercises �����������������������������������������������������������������������92
Case Study: Approximating Square Roots ���������������������������92
Summary �����������������������������������������������������������������������96
Review Questions ������������������������������������������������������������97
Projects��������������������������������������������������������������������������99

CHAPTER 4 S t r in g s an d Text Fi l es ����������������������������� 102


Accessing Characters and Substrings in Strings ��������������� 103
The Structure of Strings ��������������������������������������������� 103
The Subscript Operator����������������������������������������������� 104
Slicing for Substrings ������������������������������������������������ 105
Testing for a Substring with the in Operator ����������������� 105
Exercises �������������������������������������������������������������������� 106
Data Encryption ����������������������������������������������������������� 106
Exercises �������������������������������������������������������������������� 109
Strings and Number Systems ����������������������������������������� 109
The Positional System for Representing Numbers����������� 110
Converting Binary to Decimal �������������������������������������� 111
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Converting Decimal to Binary �������������������������������������� 112


Conversion Shortcuts ������������������������������������������������ 112
Octal and Hexadecimal Numbers ��������������������������������� 113
Exercises �������������������������������������������������������������������� 114
String Methods ������������������������������������������������������������ 115
vi Exercises �������������������������������������������������������������������� 118
Text Files �������������������������������������������������������������������� 118
Text Files and Their Format����������������������������������������� 118
Writing Text to a File �������������������������������������������������� 119
Writing Numbers to a File�������������������������������������������� 119
Reading Text from a File ��������������������������������������������� 120
Reading Numbers from a File �������������������������������������� 121
Accessing and Manipulating Files and Directories
on Disk ������������������������������������������������������������������ 122
Exercises �������������������������������������������������������������������� 125
Case Study: Text Analysis����������������������������������������������� 126
Summary �������������������������������������������������������������������� 130
Review Questions ��������������������������������������������������������� 131
Projects����������������������������������������������������������������������� 132

CHAPTER 5 Lis t s an d Dict io nari es ����������������������������� 134


Lists �������������������������������������������������������������������������� 135
List Literals and Basic Operators��������������������������������� 135
Replacing an Element in a List ������������������������������������ 138
List Methods for Inserting and Removing Elements��������� 138
Searching a List �������������������������������������������������������� 140
Sorting a List ����������������������������������������������������������� 140
Mutator Methods and the Value None ��������������������������� 141
Aliasing and Side Effects �������������������������������������������� 141
Equality: Object Identity and Structural
Equivalence ������������������������������������������������������������ 143
Example: Using a List to Find the Median
of a Set of Numbers ������������������������������������������������ 143
Tuples ��������������������������������������������������������������������� 144
Exercises �������������������������������������������������������������������� 145
Defining Simple Functions ��������������������������������������������� 146
The Syntax of Simple Function Definitions ��������������������� 146
Parameters and Arguments����������������������������������������� 147
The return Statement����������������������������������������������� 147
Boolean Functions ����������������������������������������������������� 148
Defining a main Function �������������������������������������������� 148
Exercises �������������������������������������������������������������������� 149
Case Study: Generating Sentences ��������������������������������� 150
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Dictionaries ����������������������������������������������������������������� 153


Dictionary Literals ����������������������������������������������������� 153
Adding Keys and Replacing Values�������������������������������� 154
Accessing Values ������������������������������������������������������ 154
Removing Keys ��������������������������������������������������������� 155
Traversing a Dictionary����������������������������������������������� 155 vii
Example: The Hexadecimal System Revisited����������������� 156
Example: Finding the Mode of a List of Values ��������������� 157
Exercises �������������������������������������������������������������������� 158
Case Study: Nondirective Psychotherapy�������������������������� 159
Summary �������������������������������������������������������������������� 163
Review Questions ��������������������������������������������������������� 164
Projects����������������������������������������������������������������������� 165

CHAPTER 6 Des ig n w it h F u ncti ons ����������������������������� 167


A Quick Review of What Functions Are and How
They Work ����������������������������������������������������������������� 168
Functions as Abstraction Mechanisms �������������������������� 169
Functions Eliminate Redundancy����������������������������������� 169
Functions Hide Complexity ������������������������������������������ 170
Functions Support General Methods with Systematic
Variations ��������������������������������������������������������������� 170
Functions Support the Division of Labor ����������������������� 171
Exercises �������������������������������������������������������������������� 171
Problem Solving with Top-Down Design����������������������������� 172
The Design of the Text-Analysis Program����������������������� 172
The Design of the Sentence-Generator Program�������������� 173
The Design of the Doctor Program�������������������������������� 174
Exercises �������������������������������������������������������������������� 176
Design with Recursive Functions�������������������������������������� 176
Defining a Recursive Function�������������������������������������� 176
Tracing a Recursive Function �������������������������������������� 177
Using Recursive Definitions to Construct Recursive
Functions ��������������������������������������������������������������� 178
Recursion in Sentence Structure����������������������������������� 179
Infinite Recursion ������������������������������������������������������ 179
The Costs and Benefits of Recursion����������������������������� 180
Exercises �������������������������������������������������������������������� 182
Case Study: Gathering Information from a File System�������� 183
Managing a Program’s Namespace ��������������������������������� 190
Module Variables, Parameters, and Temporary
Variables����������������������������������������������������������������� 190
Scope ��������������������������������������������������������������������� 191
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Lifetime�������������������������������������������������������������������� 192
Using Keywords for Default and Optional Arguments�������� 193
Exercises �������������������������������������������������������������������� 194
Higher-Order Functions�������������������������������������������������� 195
Functions as First-Class Data Objects��������������������������� 195
viii Mapping�������������������������������������������������������������������� 196
Filtering�������������������������������������������������������������������� 197
Reducing ����������������������������������������������������������������� 197
Using lambda to Create Anonymous Functions �������������� 198
Creating Jump Tables�������������������������������������������������� 199
Exercises �������������������������������������������������������������������� 199
Summary �������������������������������������������������������������������� 200
Review Questions ��������������������������������������������������������� 202
Projects����������������������������������������������������������������������� 203

CHAPTER 7 S im ple Gr aph ics and Image Processi ng ������� 205


Simple Graphics����������������������������������������������������������� 206
Overview of Turtle Graphics����������������������������������������� 206
Turtle Operations ������������������������������������������������������ 207
Setting Up a turtle.cfg File and Running IDLE����������������� 209
Object Instantiation and the turtle Module ������������������ 210
Drawing Two-Dimensional Shapes �������������������������������� 212
Examining an Object’s Attributes ��������������������������������� 213
Manipulating a Turtle’s Screen�������������������������������������� 214
Taking a Random Walk ���������������������������������������������� 214
Colors and the RGB System����������������������������������������� 215
Example: Filling Radial Patterns with Random
Colors�������������������������������������������������������������������� 216
Exercises �������������������������������������������������������������������� 218
Case Study: Recursive Patterns in Fractals����������������������� 218
Image Processing �������������������������������������������������������� 222
Analog and Digital Information�������������������������������������� 223
Sampling and Digitizing Images ����������������������������������� 223
Image File Formats����������������������������������������������������� 224
Image-Manipulation Operations ������������������������������������ 224
The Properties of Images�������������������������������������������� 225
The images Module ��������������������������������������������������� 225
A Loop Pattern for Traversing a Grid����������������������������� 228
A Word on Tuples ������������������������������������������������������ 229
Converting an Image to Black and White ����������������������� 230
Converting an Image to Grayscale�������������������������������� 231
Copying an Image ����������������������������������������������������� 232
Blurring an Image ������������������������������������������������������ 233
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Edge Detection ��������������������������������������������������������� 234


Reducing the Image Size �������������������������������������������� 235
Exercises �������������������������������������������������������������������� 237
Summary �������������������������������������������������������������������� 237
Review Questions ��������������������������������������������������������� 238
Projects����������������������������������������������������������������������� 240 ix

CHAPTER 8 G r aph ical Us er Inter faces ������������������������� 244


The Behavior of Terminal-Based Programs and ­GUI-Based
Programs ������������������������������������������������������������������ 245
The Terminal-Based Version����������������������������������������� 246
The GUI-Based Version ����������������������������������������������� 246
Event-Driven Programming ������������������������������������������ 248
Exercises �������������������������������������������������������������������� 249
Coding Simple GUI-Based Programs �������������������������������� 249
A Simple “Hello World” Program����������������������������������� 249
A Template for All GUI Programs����������������������������������� 251
The Syntax of Class and Method Definitions ������������������ 251
Subclassing and Inheritance as Abstraction
Mechanisms ����������������������������������������������������������� 252
Exercises �������������������������������������������������������������������� 253
Windows and Window Components����������������������������������� 253
Windows and Their Attributes �������������������������������������� 253
Window Layout����������������������������������������������������������� 254
Types of Window Components and Their Attributes��������� 256
Displaying Images ����������������������������������������������������� 257
Exercises �������������������������������������������������������������������� 259
Command Buttons and Responding to Events�������������������� 260
Exercises �������������������������������������������������������������������� 262
Input and Output with Entry Fields����������������������������������� 262
Text Fields ��������������������������������������������������������������� 262
Integer and Float Fields for Numeric Data ��������������������� 264
Using Pop-Up Message Boxes�������������������������������������� 265
Exercises �������������������������������������������������������������������� 267
Defining and Using Instance Variables ����������������������������� 267
Exercises �������������������������������������������������������������������� 269
Case Study: The Guessing Game Revisited����������������������� 269
Other Useful GUI Resources�������������������������������������������� 273
Using Nested Frames to Organize Components�������������� 273
Multi-Line Text Areas �������������������������������������������������� 275
File Dialogs �������������������������������������������������������������� 277
Obtaining Input with Prompter Boxes����������������������������� 280
Check Buttons����������������������������������������������������������� 281
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Radio Buttons ����������������������������������������������������������� 282


Keyboard Events�������������������������������������������������������� 284
Working with Colors��������������������������������������������������� 285
Using a Color Chooser ����������������������������������������������� 287
Summary �������������������������������������������������������������������� 289
x Review Questions ��������������������������������������������������������� 289
Projects����������������������������������������������������������������������� 290

CHAPTER 9 Des ig n w it h Clas ses �������������������������������� 293


Getting Inside Objects and Classes ��������������������������������� 294
A First Example: The Student Class����������������������������� 295
Docstrings ��������������������������������������������������������������� 297
Method Definitions����������������������������������������������������� 297
The __init __ Method and Instance Variables����������������� 298
The __str __ Method �������������������������������������������������� 299
Accessors and Mutators��������������������������������������������� 299
The Lifetime of Objects����������������������������������������������� 299
Rules of Thumb for Defining a Simple Class ������������������ 300
Exercises �������������������������������������������������������������������� 301
Case Study: Playing the Game of Craps��������������������������� 301
Data-Modeling Examples������������������������������������������������ 309
Rational Numbers ������������������������������������������������������ 309
Rational Number Arithmetic and Operator Overloading����� 311
Comparison Methods�������������������������������������������������� 312
Equality and the __eq__ Method����������������������������������� 313
Savings Accounts and Class Variables �������������������������� 314
Putting the Accounts into a Bank ��������������������������������� 317
Using pickle for Permanent Storage of Objects����������� 319
Input of Objects and the try-except Statement����������� 320
Playing Cards ����������������������������������������������������������� 321
Exercises �������������������������������������������������������������������� 324
Case Study: An ATM ����������������������������������������������������� 324
Building a New Data Structure: The Two-Dimensional Grid �� 330
The Interface of the Grid Class����������������������������������� 330
The Implementation of the Grid Class: Instance
Variables for the Data����������������������������������������������� 332
The Implementation of the Grid Class: Subscript
and Search�������������������������������������������������������������� 333
Case Study: Data Encryption with a Block Cipher �������������� 333
Structuring Classes with Inheritance and Polymorphism ����� 337
Inheritance Hierarchies and Modeling ��������������������������� 338
Example 1: A Restricted Savings Account ��������������������� 339
Example 2: The Dealer and a Player in the Game
ofRights
Copyright 2019 Cengage Learning. All Blackjack������������������������������������������������������������ 340
Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Polymorphic Methods������������������������������������������������� 344


The Costs and Benefits of Object-Oriented
Programming����������������������������������������������������������� 345
Exercises �������������������������������������������������������������������� 346
Summary �������������������������������������������������������������������� 347
Review Questions ��������������������������������������������������������� 348 xi
Projects����������������������������������������������������������������������� 349

CHAPTER 10 M u lt it h readin g , ­Networks, and Cl i ent/ Serv er


Pro g r am m in g ���������������������������������������� 352
Threads and Processes�������������������������������������������������� 353
Threads�������������������������������������������������������������������� 354
Sleeping Threads ������������������������������������������������������ 357
Producer, Consumer, and Synchronization �������������������� 358
Exercises �������������������������������������������������������������������� 364
The Readers and Writers Problem ����������������������������������� 364
Using the SharedCell Class �������������������������������������� 365
Implementing the Interface of the SharedCell Class ����� 366
Implementing the Helper Methods of the
SharedCell Class �������������������������������������������������� 368
Testing the SharedCell Class with a Counter Object ����� 369
Defining a Thread-Safe Class �������������������������������������� 370
Exercises �������������������������������������������������������������������� 371
Networks, Clients, and Servers �������������������������������������� 371
IP Addresses ������������������������������������������������������������ 372
Ports, Servers, and Clients ����������������������������������������� 373
Sockets and a Day/Time Client Script �������������������������� 373
A Day/Time Server Script�������������������������������������������� 375
A Two-Way Chat Script ����������������������������������������������� 377
Handling Multiple Clients Concurrently �������������������������� 378
Exercises �������������������������������������������������������������������� 380
Case Study: Setting Up Conversations between Doctors
and Patients �������������������������������������������������������������� 381
Summary �������������������������������������������������������������������� 386
Review Questions ��������������������������������������������������������� 387
Projects����������������������������������������������������������������������� 388

CHAPTER 11 S earch in g , ­So r ti ng, and Compl ex i ty Anal y si s� 390


Measuring the Efficiency of Algorithms����������������������������� 391
Measuring the Run Time of an Algorithm ����������������������� 391
Counting Instructions�������������������������������������������������� 394
Exercises
Copyright 2019 Cengage Learning. ��������������������������������������������������������������������
All Rights Reserved. 396
May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
contents

Complexity Analysis ������������������������������������������������������ 397


Orders of Complexity�������������������������������������������������� 397
Big-O Notation����������������������������������������������������������� 399
The Role of the Constant of Proportionality�������������������� 400
Measuring the Memory Used by an Algorithm����������������� 400
xii Exercises �������������������������������������������������������������������� 401
Search Algorithms �������������������������������������������������������� 401
Search for a Minimum ������������������������������������������������ 401
Sequential Search of a List ����������������������������������������� 402
Best-Case, Worst-Case, and Average-Case
Performance����������������������������������������������������������� 403
Binary Search of a List����������������������������������������������� 403
Exercises �������������������������������������������������������������������� 405
Basic Sort Algorithms ��������������������������������������������������� 405
Selection Sort����������������������������������������������������������� 406
Bubble Sort �������������������������������������������������������������� 407
Insertion Sort ����������������������������������������������������������� 408
Best-Case, Worst-Case, and Average-Case
Performance Revisited ��������������������������������������������� 410
Exercises �������������������������������������������������������������������� 410
Faster Sorting�������������������������������������������������������������� 411
Quicksort ����������������������������������������������������������������� 411
Merge Sort��������������������������������������������������������������� 415
Exercises �������������������������������������������������������������������� 418
An Exponential Algorithm: Recursive Fibonacci ����������������� 419
Converting Fibonacci to a Linear Algorithm����������������������� 420
Case Study: An Algorithm Profiler ����������������������������������� 421
Summary �������������������������������������������������������������������� 427
Review Questions ��������������������������������������������������������� 428
Projects����������������������������������������������������������������������� 429

APP ENDIX A Pyt h o n Res o u rce s ���������������������������������� 432

APP ENDIX B In s t allin g t h e i mages


an d br ee zy py th ongui Li brari es �������������� 434

APP ENDIX C T h e API f o r Im age Processi ng������������������� 436

APP ENDIX D Tr an s it io n f ro m Py thon to Jav a and C++ ����� 438

Glo s s ar y ���������������������������������������������� 439

In dex ���������������������������������������������������� 455


Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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
xiii

“Everyone should learn how to code.” That’s my favorite quote from Suzanne Keen, the
Thomas Broadus Professor of English and Dean of the College at Washington and Lee Uni-
versity, where I have taught computer science for more than 30 years. The quote also states
the reason why I wrote the first edition of Fundamentals of Python: First Programs, and why
I now offer you this second edition. The book is intended for an introductory course in pro-
gramming and problem solving. It covers the material taught in a typical Computer Science 1
course (CS1) at the undergraduate or high school level.
This book covers five major aspects of computing:
1. Programming Basics—Data types, control structures, algorithm development, and
program design with functions are basic ideas that you need to master in order to
solve problems with computers. This book examines 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 dic-
tionaries. This book introduces you to these commonly used data structures and
includes examples that illustrate criteria for selecting the appropriate data struc-
tures 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 pro-
gramming and problem solving is to create interesting programs with real-world
applications. In this book, you’ll begin by creating applications that involve numeri-
cal 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

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
P r e f a c e Why Python?

one does not restrict itself to problems involving numbers and text. Most contem-
porary applications involve graphical user interfaces, event-driven programming,
graphics, image manipulation, and network communications. These topics are not
consigned to the margins, but are presented in depth after you have mastered the
basics of programming.
xiv

Why Python?
Computer technology and applications have become increasingly more sophisticated over
the past three decades, and so has the computer science curriculum, especially at the intro-
ductory level. Today’s students learn a bit of programming and problem solving, and they
are then expected to move quickly into topics like software development, complexity analy-
sis, and data structures that, 30 years ago, were relegated to advanced courses. In addition,
the ascent of object-oriented programming as the dominant paradigm of problem solving
has led instructors and textbook authors to implant powerful, industrial-strength program-
ming languages such as C++ and Java in the introductory curriculum. As a result, instead
of experiencing the rewards and excitement of solving problems with computers, beginning
computer science students often become overwhelmed by the combined tasks of mastering
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
studying 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 conventional notation found in
algebra. Thus, students can spend less time learning the syntax of a programming lan-
guage 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 programming 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 interpret-
er’s prompts to allow the programmer to try out experimental code and receive immedi-
ate 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 computing 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 community, and expertise in
Python programming has great résumé value.

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Organization of the Book pr e f a c e

To summarize these benefits, Python is a comfortable and flexible vehicle for expressing
ideas about computation, both for beginners and for experts. 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 curriculum. Most importantly, beginning students
will spend less time staring at a computer screen and more time thinking about interesting
problems to solve. xv

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 hardware and software, followed
by an extended discussion of the history of computing, sets the context for computational
problem solving.
Chapters 2 and 3 cover the basics of problem solving and algorithm development 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 dictionaries. These
data structures are both remarkably easy to manipulate in Python and support some inter-
esting applications. Chapter 5 also introduces simple function definitions as a way of orga-
nizing 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 problems. Details of namespace
organization (parameters, temporary variables, and module variables) and communica-
tion among software components are discussed. A 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 programs. ­Special
attention is paid to the application programming interface (API), 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.
Chapter 8 introduces the definition of new classes to construct graphical user interfaces
(GUIs). The chapter 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 design of GUI-based applications using the model/view pattern.
The initial approach to defining new classes in this chapter is unusual for an introductory

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
P r e f a c e Special Features

textbook: students learn that the easiest way to define a new class is to customize an exist-
ing class using subclassing and inheritance.
Chapter 9 continues the exploration of object-oriented design with the definition of entirely
new classes. Several examples of simple class definitions from different application domains
are presented. Some of these are then integrated into more realistic applications, to show
xvi how object-oriented software components can be used to build complex systems. Emphasis
is on designing appropriate interfaces for classes that exploit polymorphism.
Chapter 10 covers advanced material related to several important areas of computing:
concurrent programming, networks, and client/server applications. This chapter thus
gives students challenging experiences near the end of the first course. Chapter 10 intro-
duces multithreaded 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. 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 prob-
lems. 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 develop-
ment life cycle, case studies are discussed in the framework 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 program-
ming projects.
•• Chapter objectives and chapter summaries—Each chapter begins with a set of learning
objectives and ends with a summary of the major concepts covered 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.
•• Exercises—Most major sections of each chapter end with exercise questions that rein-
force the reading by asking basic questions about the material in the section. Each chap-
ter ends with a set of review exercises.
•• Programming projects—Each chapter ends with a set of programming projects of vary-
ing difficulty.

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Instructor Resources pr e f a c e

•• 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.cengage.com, or at http://home.wlu
.edu/~lambertk/python/
•• A software toolkit for GUI programming—This book comes with an open-source
Python toolkit for the easy GUI programming introduced in Chapter 8. The toolkit can xvii
be obtained from the student downloads page on www.cengage.com, or at http://home
.wlu.edu/~lambertk/breezypythongui/
•• Appendices—Four appendices include information on obtaining Python resources,
installing the toolkits, and using the toolkits’ interfaces.

New in This Edition


The most obvious change in this edition is the addition of full color. All program examples
include the color coding used in Python’s IDLE, so students can easily identify program
elements such as keywords, program comments, and function, method, and class names.
Several new figures have been added to illustrate concepts, and many exercises and pro-
gramming projects have been reworked. The brief history of computing in Chapter 1 has
been brought up to date. A discussion of a Grid type has been included to give students
exposure to a two-dimensional data structure. The book remains the only introductory
Python text with a thorough introduction to realistic GUI programming. The chapter
on GUIs (Chapter 8) now uses the breezypythongui toolkit to ease the introduction of
this topic. The chapter on GUIs has also been placed ahead of the chapter on design with
classes (Chapter 9). This arrangement allows students to explore the customizing of exist-
ing classes with GUI programming before they tackle the design of entirely new classes in
the following chapter. Finally, a new section on the readers and writers problem has been
added to Chapter 10, to illustrate thread-safe access to shared resources.

Instructor Resources
MindTap
MindTap activities for Fundamentals of Python: First Programs are designed to help stu-
dents master the skills they need in today’s workforce. Research shows employers need
critical thinkers, troubleshooters, and creative problem-solvers to stay relevant in our
fast-paced, technology-driven world. MindTap helps you achieve this with assignments
and activities that provide hands-on practice and real-life relevance. Students are guided
through assignments that help them master basic knowledge and understanding before
moving on to more challenging problems.
All MindTap activities and assignments are tied to defined unit learning objectives.
­Hands-on coding labs provide real-life application and practice. Readings and dynamic
visualizations support the lecture, while a post-course assessment measures exactly how

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
P r e f a c e We Appreciate Your Feedback

much a student has learned. MindTap provides the analytics and reporting to easily see
where the class stands in terms of progress, engagement, and completion rates. Use the
content and learning path as-is or pick-and-choose how our materials will wrap around
yours. You control what the students see and when they see it. Learn more at http://www
.cengage.com/mindtap/.
xviii

Instructor Companion Site


The following teaching tools are available for download at the Companion Site for this text.
Simply search for this text at www.cengagebrain.com and choose "Instructor Downloads."
An instructor login is required.
•• Instructor’s Manual: The Instructor’s Manual that accompanies this textbook includes
additional instructional material to assist in class preparation, including items such as
Overviews, Chapter Objectives, Teaching Tips, Quick Quizzes, Class Discussion Top-
ics, Additional Projects, Additional Resources, and Key Terms. A sample syllabus is also
available.
•• Test Bank: Cengage Testing Powered by Cognero is a flexible, online system that allows
you to:
•• author, edit, and manage test bank content from multiple Cengage solutions
•• create multiple test versions in an instant
•• deliver tests from your LMS, your classroom, or wherever you want
•• PowerPoint Presentations: This text provides PowerPoint slides to accompany each
chapter. Slides may be used to guide classroom presentations, to make available to stu-
dents for chapter review, or to print as classroom handouts. Files are provided for every
figure in the text. Instructors may use the files to customize PowerPoint slides, illustrate
quizzes, or create handouts.
•• Solutions: Solutions to all programming exercises are available. If an input file is
needed to run a programming exercise, it is included with the solution file.
•• Source Code: The source code is available at www.cengagebrain.com. If an input file is
needed to run a program, it is included with the source code.

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 http://support.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.

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Dedication pr e f a c e

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. I am also grateful
to the many students and colleagues at Washington and Lee University who have used this
book and given helpful feedback on it over the life of the first edition.
xix
In addition, I would like to thank the following reviewers for the time and effort they
contributed to Fundamentals of Python: Steven Robinett, Great Falls College Montana
State University; Mark Williams, University of Maryland Eastern Shore; Andrew ­Danner,
­Swarthmore College; Susan Fox, Macalester College; Emily Shepard, Central Carolina
Community College.
Also, thank you to the individuals at Cengage who helped to assure that the content of
all data and solution files used for this text were correct and accurate: John Freitas, MQA
­Project Leader, and Danielle Shaw, MQA Tester.
Finally, thanks to several other people whose work made this book possible: Kate Mason,
Associate Product Manager, Cengage; Natalie Pashoukos, Senior Content Developer,
­Cengage; and Jennifer Feltri-George, Senior Content Project Manager, Cengage. I also
want to thank Scarlett Lindsay for her superb copyediting of the book and Chandrasekar
­Subramanian for an excellent job managing the paging of the project.

Dedication
To my good friends, Lesley and David Novack
Kenneth A. Lambert
Lexington, VA

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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 ­computer’s architecture
Summarize a brief history of computing
Compose and run a simple Python program

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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

As a reader of this book, you almost certainly have played a video game and listened to
digital music. It’s likely that you have watched a digital movie after preparing a snack in a
microwave oven. Chances are that today you will make a phone call, send or receive a text
message, take a photo, or consult your favorite social network on a cell phone. You and your
friends have most likely used a desktop computer or a laptop computer to do some signifi-
2
cant coursework in high school or college.
These activities rely on something in common: computer technology. Computer technol-
ogy is almost everywhere, not only in our homes but also in our schools and in the places
where we work and play. Computer technology plays an important role in entertainment,
education, medicine, manufacturing, communications, government, and commerce. It
has been said that we have digital lifestyles and that we live in an information age with an
information-based economy. Some people even claim that nature itself performs computa-
tions on information structures present in DNA and in the relationships among subatomic
particles.
It’s difficult to imagine our world without computation, 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 for thousands of years, and that computer technology has pervaded
the world as we know it for only the past 30 years or so.
In the following chapters, you will learn about computer science, which is the study of com-
putation 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.

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.

Algorithms
People computed long before the invention of modern computing devices, and many con-
tinue 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.
According to one method, the first step is to compute the difference between the pur-
chase price and the amount of money that the customer gives the merchant. The result of

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Two Fundamental Ideas of Computer Science

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.
According to another method, the merchant starts with the purchase price and goes toward
the amount given. First, coins are selected to bring the price to the next dollar amount (in 3
this case, $0.61 5 3 dimes, 1 nickel, and 4 pennies), then dollars are selected to bring the
price to the next 5-dollar amount (in this case, $2), and then, in this case, a $5 bill completes
the transaction. As you will see in this book, there can be many possible methods or algo-
rithms that solve the same problem, and the choice of the best one is a skill you will acquire
with practice.
Few people can subtract three-digit numbers without resorting to some manual 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 specific steps involved. Making such
lists to solve problems is something computer 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 num-
ber 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 col-
umn to the left, and go back to Step 3.
If the computing agent (in this case a human being) follows each of these simple steps cor-
rectly, 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 cor-
rectness 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

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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

problem. The algorithm is also one of the fundamental ideas of computer science. An algo-
rithm 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
4 action described by the instruction can be performed effectively or be executed
by a computing agent. For example, any computing agent capable of arithmetic can
compute the difference between two digits. So an algorithmic step that says “com-
pute 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.
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 algorithm 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 component parts is one
of the main jobs of a computer programmer. Once we write an algorithm to describe a par-
ticular type of computation, we can build a machine 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 computers, 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 algorithmic thinking are critical
underpinnings of any computer system.

Information Processing
Since human beings first learned to write several thousand years ago, they have pro-
cessed 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

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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.
Two Fundamental Ideas of Computer Science

Greece; to the printed words in the books, newspapers, and magazines mass-produced
since the European Renaissance; to the abstract symbols of modern mathematics and sci-
ence 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, information is also commonly referred to as data. But what is
information? 5
Like mathematical calculations, information processing can be described with algorithms.
In our earlier example of making change, the subtraction steps involved manipulating sym-
bols used to represent numbers and money. In carrying out the instructions of any algo-
rithm, a computing agent manipulates information. 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 algo-
rithms in a form that can be executed effectively and efficiently by machines. They have
also designed real machines, called electronic digital computers, which are capable of exe-
cuting 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 commu-
nication 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.

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 making change
(counting out the coins and bills).
3. Write an algorithm that describes a common task, such as baking a cake or operat-
ing 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 laptop 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.)

Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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

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
6 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).

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, a trackpad, a microphone, and a touchscreen. Common out-
put devices include a monitor and speakers. Computers can also communicate with the
external world through various ports that connect them to networks and to other devices
such as smartphones and digital cameras. The purpose of most input devices is to convert
information that human beings deal with, such as text, images, and sounds, into informa-
tion for computational processing. The purpose of most output devices is to convert the
results of this processing back to human-usable form.
Computer memory is set up to represent and store information in electronic form. Specifi-
cally, 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 discovered how to represent any information, including text, images, and sound, in
binary form.
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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 Structure of a Modern Computer System

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 collection. We have just developed a
tiny model of computer memory. The 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).
7

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 sim-
ple logical, arithmetic, and control operations. The CPU executes an algorithm by fetching its
binary instructions from memory, decoding them, and executing them. Executing an instruc-
tion might involve fetching other binary information—the data—from memory as well.
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 permanent type of memory is called external or s­ econdary
­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 different technol-
ogy, 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.

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 algorithms into a computer’s
Copyright 2019 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2019 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
The central part of the Indian Ocean is well known CYCLONES
as the region of cyclones, and these dreaded storms
often include in their revolving course the islands of Mauritius and
Réunion, and occasionally touch the eastern shores of Madagascar.
A notable example of this was the cyclone of November 1912, which
stranded the S.S. Salazie, and wrecked Diego-Suarez and many
villages in the north of the island. It is very seldom, however, that
these storms reach the interior; but in the month of February 1876 a
cyclone did ascend to the upper region of the island and did
considerable damage. With my wife and children I was staying for a
holiday at that time at Andràngalòaka, a small village on the edge of
the upper forest, but five or six miles south of Ankèramadìnika,
where our good friend, Dr A. Davidson, had a country house, which
he often placed at the disposal of ourselves and other friends; and
never shall we forget the experiences of that night of peril.
It was a Sunday evening and the sun set with a radiance which
covered the whole sky with a crimson glow, in a very remarkable
manner. We settled down after our evening meal for a little reading
aloud, but the wind rose rapidly, and after a time the roar was so
great that we could not go on. We found that its violence increased,
and at length we perceived that it was slowly changing in its
direction. We went to bed, but not to sleep, for the rain poured in
from the roof, and the howl of the wind made sleep impossible. We
lay trembling on our beds, fearing every now and then, as a more
violent burst shook the house, that it would be blown down over us,
and we buried in its ruins. Such would have been the case, I believe,
had not the gables been built of burnt brick and strengthened by the
chimney-stacks. During the night the metal roofing of the verandah
was torn off with a fearful clatter, and soon after dawn—and how
long that dawn seemed in coming!—the outer roof of the house,
which was of grass, fixed over the tiled roof, was bodily seized by the
wind and carried off altogether with its timbers, with a great crash,
and then we thought the house itself was all going. But towards nine
a.m. the wind gradually subsided, after having blown from about
three-quarters of the circle of the compass.
Scores of country chapels as well as houses were unroofed and
greatly damaged by this storm. A day or two after it we tried to take
one of our usual walks through the woods, but the paths were almost
obliterated by fallen trees and branches. In the valleys scores of
great trees had been torn up by the roots, with masses of soil
clinging to them; in other places they had been broken off short,
snapped as if they had been mere twigs; and in the prostrate
branches were numbers of arboreal creatures—chameleons, lizards,
serpents and tree-frogs—dashed down from their homes. It was all
striking evidence of the force with which the fierce wind had roared,
especially up the valleys, and had laid low everything in its path.
[13] For most of the information here given about the Madagascar
bee, I am again indebted to the Rev. C. P. Cory, formerly of the
Anglican Mission in Madagascar.
CHAPTER XII

RAMBLES IN THE UPPER FOREST

T
HERE are a number of paths in the forest which may be
followed from the sanatorium, north, east and south, and with
a considerable variety of scene. But it is easy to get lost in
them, for I remember one day when a party of us set out for a
morning’s walk, but could not find our way back, although we often
caught sight of the house; and it was late in the afternoon before we
at length got home, very tired and very hungry. Two of our friends,
who were well acquainted with the neighbourhood, were lost in paths
not very far from the sanatorium, and had to spend the night in the
woods, making as comfortable a resting-place as they could with
leaves and bracken, but getting no sleep from the multitude of
mosquitoes. And a curious circumstance was, that the Malagasy
from the house, who came out to seek for them, were afraid either to
shout out loud to them, or to show the lights they carried, for fear of
offending the lòlo, or spirits, which they think haunt the woods. Had
they done either of these things, our friends would probably have
escaped being benighted. Happily, the time of this adventure was in
the dry season, or it might have had serious consequences.
From what has been said in Chapters IV. and V. about the difficult
paths through the chief forest, it is not strange that the Malagasy
have considerable dread of it and do not share in our admiration of
its beauties. So one of their proverbs says: “Roa lahy miditra ala: ka
izy tokiko, ary izaho tokiny”—that is, “Two men entering the forest:
it’s ‘He’s my confidence, and I am his’”; the fact is that both are
afraid. It is to them the “dark forest,” full of mystery and fear, and it
may easily be imagined that before any practicable roads were made
through it, it had much to inspire dread. One of the native hymns,
often sung when the natives have friends going away to a distance,
prays for protection for them in the forest and also in crossing the
rivers, on account of the many things in both which may injure the
traveller.[14]
It would probably be a very serious matter for a A MADAGASCAR
European to be lost for long in a Madagascar forest, FOREST
for he would be entirely at a loss for food, and would most likely be
unable to produce fire to cook anything he could find. To a Malagasy,
however, especially one living in the neighbourhood of the woods, it
would not matter so much, as there are several species of yam,
which he would easily find. These Ovinàla are climbing plants
common in the forest, belonging to the genus Dioscorea, and have
very large edible tubers, which are much sought after by the people;
their taste is similar to other yams which are so largely used as food
in other parts of the world. In Drury’s “Adventures,” he speaks
frequently of procuring these yams in the south-western forests; for,
living many years, as he did, like a native in that part of the island, he
became well versed in woodcraft and could live as the people lived.
A European would be equally puzzled as to obtaining fire to cook
his yams, were he so fortunate as to find any; but a forest-dwelling
Malagasy could easily produce fire by friction. Choosing two pieces
of a particular kind of wood, he would cut one to the shape of a
round stick with a pointed end; the other he would make into a flatter
piece, in which a slight groove is cut. Taking hold of the pointed stick,
the operator twirls it first one way and then another, until the friction
produces smoke and then fire, which is communicated to a little
tinder placed close to the point. Gently blowing upon the spark which
is produced, the tinder bursts into flame, the whole operation
occupying only a few minutes. There are special words for this mode
of obtaining fire: mamòsitra, which is also used for the boring of a
hole by an insect, or a chameleon, to deposit its eggs; and miraingy,
the pieces of wood being called raingy. But it may be feared that the
universal use of Swedish matches will soon render this means of
producing fire one of the lost arts.
To tend a fire is, in Malagasy, to misòrona àfo; and since misòrona
also means “to exercise a priestly function,” it looks as if this word or
phrase was a relic of ancient reverence for fire as a sacred thing, a
feeling which is found in the customs and speech of many peoples.
In several directions there are beautiful waterfalls, to WATERFALLS
which a pleasant picnic excursion may be made. One
of these is called “Tsi-màharé-rìtsoka,” which means, “Where a
whisper cannot be heard,” for indeed, when near it, you must bawl
as loud as you can to be heard at all; this fall is a succession of
cascades, coming down from a considerable height. At another
place a large body of water pours at one sweep over a great ledge of
rock, perhaps thirty feet deep. And along the automobile road, only a
few yards from it up a little valley leading into the main valley of the
river Mandràka, we were fortunate one day to discover a most lovely
waterfall of considerable height in the midst of dense wood, with a
large pool of water at its foot, where a delightful bathe might be
taken; an ideal place for a summer day. But the largest and grandest
waterfall, and within a little over an hour’s walk from the sanatorium,
is really an artificial one; for in making the automobile road to
Tamatave along the Mandràka valley, the river was diverted from a
circuitous course over a number of rapids, and brought by a short-
cutting over a nearly sheer fall of about a hundred and fifty feet,
where it pours down a magnificent body of water, with a roar and
clouds of spray that wet everything for a long way round. The sides
of the cutting are being rapidly covered with vegetation from the
constant moisture, so that in a short time it will have all the effect of a
natural fall. The noise is tremendous, and the fall can be seen from
several points on the main road.
At the foot of the second of the waterfalls just FROGS
mentioned I was fortunate enough to see a rather rare
frog, which is peculiar to Madagascar. This little creature is only an
inch long, as regards the body, but on that and its long hind legs
there are semicircular patches of bright red on a black ground, so
that it is very conspicuous (Mantella baroni) (see illustration). There
is also a much larger frog, three inches in length, with hind legs quite
six inches long (Rhacophoras albilabris); this species appears to be,
in part at least, arboreal as well as aquatic, as its toes are furnished
with little disks instead of claws (see illustration). He is, however, a
giant compared with the majority of the frogs found in the island,
which are not very different in colouring or size from the common
English species. These creatures are very plentiful in the rice-fields,
and as one walks along the vàlamparìa, or little banks separating the
fields, the frogs jump off and “plop” into the water at every step one
takes. In the early morning, after a rainy night, the noise of their
croaking is very loud, almost deafening, as they apparently find the
increased depth of water much to their liking.
From some small structural peculiarities, many of the Madagascar
frogs have been arranged in a distinct genus, called Mantidactylus,
and of this genus at least sixteen species have been described. Of
the widely distributed genus Rana, one species, R. fasciata, is said
by a careful observer to build a kind of nest. These frogs construct
regular passages under the grass during the dry season; their paths
are made as regularly as those of a mole, by the little creatures
pressing down the short grass near the earth, and drawing together
the longer blades, thus rendering them invisible. The nests are from
eight to ten inches in diameter by four in height, and made
ingeniously by weaving the layers of grass together. When
frightened, these frogs throw out a limpid stream of water, which has
been stored up in time of need, as in very dry weather, and which is
distributed over the body, so as to keep the whole of it moist. The
tree-frogs are very pretty little creatures, their light green colour
exactly matching that of the leaves on which they live, so that it is
difficult to detect their presence, except by close inspection. Their
toes end in small disks, so as to adhere closely to the smooth
surface of the leaves.
We have already seen that many of the living creatures of
Madagascar gain great protection from enemies from the
assimilation of their colour to that of their surroundings. This is the
case also with many species of grasshopper and of mantis. You see
an insect with bright scarlet wings flit by you and settle on a bush;
wanting to observe it more closely, you try to find it, but it has
disappeared, and not a vestige of bright colour is to be seen. Still, if
you are patient and search carefully, you may presently see a mantis
moving its head about in an uncanny fashion, and its fore legs held
up in a mock devotional attitude, from which its specific name of
Religiosa has been given it. But the scarlet wings are folded under
its green wing-cases so as to be perfectly unseen, and these
coverings are just like a leaf, the rest of its body being exactly the
colour of its resting-place. In some of the grasshoppers, this mimicry
of vegetable forms is still more wonderful. Here is one which
resembles green grass, and its body, legs, wing-sheaths and
antennæ are all as like grass as they can possibly be. But here again
is another kind, whose body is equally imitative of dry grass, and so
all parts of it are just like the stalks or the blades of yellowish-brown
grass, dried up during the cold season. Even the eyes are imitative,
and exactly resemble a small brown seed, such as many grasses
bear.
There are many species of beetles to be seen, BEETLES
although none of them are very handsome or
conspicuous. The most common kind is a broad flat insect, about an
inch long and dull dark brown in colour, which crosses one’s path at
every step. Another is seen chiefly on the bushes, a smaller insect,
but bright shining jet-black. Another, which appears as if it mimicked
a wasp in its habit of flight, is shot with brown and green, with very
long legs, and is constantly taking short flights or running rapidly.
Another one, but much more rare, has golden-green and metallic
tints on its wing-cases. But the insect which has puzzled us most is
one that I have seen on a large bush of Ròimémy, a plant with
acacia-like leaves, with prickles along the leaf-stalks. This beetle is
about five-eighths of an inch long, and almost hemispherical in
shape. It is warm reddish-brown in colour, with a line of black and
then of yellow next the head, and is perfectly flat below. These
insects cluster closely, as thick as they can lie, in groups of from a
dozen to more than a hundred together, all round the thicker stems,
so that they look at a little distance like strings of large brown beads;
and in some of the topmost branches they form a continuous mass
for two or three feet. Amongst these shining brown insects are a few
others of quite a different colour and shape, perfectly flat, like a
minute tortoise, and of a uniform grey, exactly resembling the lichen
on the bark of the tree, and the edges of the carapace scalloped.
These grey insects are in the proportion of about one to forty or fifty
of the darker coloured ones. There are also a few individuals of the
same shape as the brown one, but yellowish-green in colour. What
these grey insects can be, and what relation they bear to the much
more numerous brown ones, I cannot make out.
Other insects, at first sight resembling beetles, are gaudily
coloured. Yonder is a bush which is conspicuous from some little
distance, from the quantity of insects clustered on it; they are about
half-an-inch long, but are most brilliant with scarlet, blue and green.
Be careful, however, how you handle them, for their scent is anything
but agreeable; and, notwithstanding their gay colours, they are, after
all, a species of bug. A beetle which I have often noticed in the
woods is an insect an inch and a half long, but with a very long
slender proboscis, with which it appears to pierce the bark of the
stems on which it rests; I think it feeds on the juices of the bush or
tree, and is probably a species of weevil (Eupholus sp?).
Mimicry, however, is not confined to Madagascar MIMICRY
animals, but also occurs among plants. Mr Baron
says: “In some marshy ground on the top of Ankàratra mountain, I
found a small whitish orchid, a few specimens of which I gathered.
After getting about half-a-dozen, I discovered, to my great surprise,
that some of them were labiate plants. I was utterly deceived,
thinking it was the same plant I was gathering all the time, so exactly
alike were the two species in almost all outward appearances. I felt
at once convinced that this was a case of mimicry. At the east foot of
the mountain I discovered a similar phenomenon, in a large labiate
plant (Salvia), strikingly similar to another orchid. No doubt the
labiate in each case mimics the orchid, not vice versa, in order to
ensure fertilisation.”
In one of our rambles near the large patch of old forest which still
remains near the L.M.S. sanatorium at Ambàtovòry I came one day
across a cluster of very large earthworms; at first sight these looked
more like a number of small snakes than worms, as they were at
least three times the size of any English worms, having about as
large a diameter as a good-sized man’s finger. They are not,
however, very common, as I have only seen them on that one
occasion; so they probably do not play the same important part in
the renewal of the soil here as Mr Darwin has shown is done by
earthworms in Europe.
Anyone who walks through the forest will notice at points where
the paths branch off a pile of bracken, branches of trees, moss, etc.
These heaps, as well as those of stones in similar positions in the
open country, are known as fànataovana. These have been formed
by passers-by throwing a stick or stone on the heap, for luck,
expressing the hope that, if on a journey, they may have a safe
return, as well as success in their undertakings. A similar custom
prevails in the eastern parts of Africa, and also in Sumatra and
Timor, and probably in other countries as well.
A walk along the upper edge of the forest, although NATIVE
at some distance from Ankèramadìnika, will bring us FOUNDRIES
to one of the native smelting and forging stations, where iron is
obtained and made into pigs for the use of blacksmiths, as well as
into various implements. Iron is very abundant in the interior of
Madagascar, indeed the whole soil over an immense extent of it is
reddened by iron oxide, and in some places there is so much
magnetite that a compass is seriously deflected and is quite
unreliable. At such a foundry one may see in use the “feather-
bellows,” which the Malagasy brought with them from their far-off
Malayan home, and which I believe is nowhere to be found but in
Madagascar and Malaysia. This consists of two cylinders, about five
feet long and six inches to eight inches wide, made from the trunks
of trees hollowed out. These are made air-tight at the lower end and
fixed in the earth in a vertical position, about eighteen inches to two
feet apart. In each cylinder a hole is made a few inches from the
ground, and in these a bamboo cane or an old musket-barrel is
inserted, the other end being fixed into the stone or clay wall of the
furnace. A piston with feather valves is fitted into each cylinder, and
the shafts or piston-rods are worked up and down alternately by a
boy or man seated on a board uniting the cylinders. In this way a
continuous blast is produced in the furnace. (Such bellows are also
used by blacksmiths.)
These foundries are always situated near a running stream of
water, so that the ore may be washed and cleared as much as
possible from earth and sand. The furnace itself is a hole about six
feet in diameter and one or two feet deep; its walls are of rough
stonework, built up three or four feet, and thickly plastered outside
with clay. Charcoal is used in smelting and, notwithstanding these
rude appliances and methods, the iron produced has been
pronounced by competent judges to be of excellent quality. Spade-
blades, knives, nails, bolts and many other articles are produced by
the native smiths; and in the construction of the Memorial Churches,
more than forty years ago, I had ornamental hinges, railings, finial
crosses, and other requisite ironwork all excellently made and
finished by Malagasy blacksmiths.

Memorial Carved Posts and Ox Horns, Bétsiléo Province


Generally the horns are of oxen killed at the funeral
Blacksmith at Work
Note the feather-piston bellows, and the man playing a single-stringed gourd guitar

Several of the paths in the forest lead down into ravines of


considerable depth and also of great beauty; the combinations of
luxuriant foliage, rushing water and lichen-embroidered rocks, ferns
and mosses are very varied, and one valley especially reminds one
of the celebrated “Fairy Glen” in North Wales. But there are
occasionally certain drawbacks even in this natural loveliness, for if
you are not very careful you may find yourself attacked by the small
leeches which lie in wait on the grass and bushes, and transfer
themselves to you as you brush by them. Before you feel any
annoyance, you may find yourself streaming with blood from the
punctures made by these little pests, which have got under your
clothing and are feeding at your expense. Happily, they do not cause
any pain worth speaking of, nor are there any unpleasant after-
effects, the only discomfort is the blood you lose and having it
outside instead of inside your skin.
While staying near the upper forest we had CRAYFISH
frequently brought to us for sale a basketful of
crayfish, which seems fairly plentiful in the streams. This species
(Astacoides madagascariensis), with its genus, is endemic in
Madagascar, and in the interior is of small size, averaging about
three inches in length; the flavour, however, is excellent, and it
makes a very good curry. In the south-east provinces, and probably
in other coast districts as well, it attains larger dimensions than the
above, being about six inches long. It is a curious fact that
crustaceans are entirely absent in the African continent, and that the
Madagascar species is much like the kind found in Australia, except
that the latter is about twice the size of Astacoides.
There is a great variety of ferns to be found in every damp place in
the valleys, from the minute hymenophyllums on the tree trunks to
the larger species of Asplenium, Osmunda, Nephrodium and many
others, up to the tree-ferns, of which there are about twenty different
kinds, and which give a special charm to the vegetation in many
places. On the eastern side of Madagascar the ferns occupy a
prominent place in the flora, there being above two hundred species
already known, and comprising no less than above thirteen per cent.
of the whole flora of that region. Among the Filici are the beautiful
gold ferns and silver ferns, the seed-vessels on the under side of the
fronds having quite the effect of the two precious metals. The young
leaves of a tree found in the forest (Eleocarpus sericeus), when dried
and pressed, form the beautiful objects known as “gold leaves.”
A large number of the forest trees yield substances VALUABLE TREES
of commercial value. Two species of climbing plants
afford india-rubber, one of the most valuable exports of the island. A
tree called Nàto supplies a bark which is largely employed by the
natives in dyeing the deep red used for their silk làmbas, especially
those used to wrap the bodies of the dead. Other trees yield various
gums and resins, one of these being the valuable gum-copal, of
which quantities are exported. From several other trees tough fibres
are obtained for the manufacture of cord and rope; while from a palm
called Vònitra the “bass fibre” or piassava is taken, which is used for
making brooms, brushes, etc. A shrub, a species of castor-oil plant,
supplies seeds which are so full of oil or fat that they are strung on a
reed like beads and are used to give light, so that it is called “the
candle-nut tree.” When one end is lit, the seeds burn steadily, giving
a light about equal to that of two good candles and leaving no ash. A
very considerable number of trees and plants are employed in
various ways by the Malagasy as medicine, both for internal and
external use; and although the virtue of some of these may be
imaginative only, there can be little doubt that in numbers of
instances these native remedies are of value. Probably a careful
examination of them would give some valuable additions to the
pharmacopœia.
Among the forest trees is a considerable number which yield
valuable timber, most of them hard and beautifully grained woods,
which are employed for cabinet-work as well as in house carpentry.
In the great palace at Antanànarìvo, the three central columns
supporting the ridge of the roof are said to be each formed of the
trunk of a single tree; the roof is a hundred and twenty feet high, and
these pillars are sunk some way in the earth. One of these timber
trees, called Vòambòana, is extensively used for making furniture—
tables, sideboards, wardrobes, writing-desks, bookshelves, etc.—
and resembles mahogany. Another tree called Hàrahàra has
extremely hard wood, and is employed for the long spade handles,
and formerly for spear shafts. One species of pine known as Hètatra,
the only example of that order in the island, gives a hard white wood
used for flooring; while ebony is procured from one or two endemic
species of Diospyros; sandalwood is also reported to be found in
certain localities.
It will easily be believed that the mysteriousness of SUPERSTITIONS
the forest has produced many superstitious notions
among the Malagasy, and they have curious stories of marvellous
creatures and monsters inhabiting these dense woods. One of these
is called Kinòly, and is said to be human in origin, for although it has
no intestines or stomach, yet in all its other parts it is like a living
person. Its eyes are red, and its nails long; and, with others of its
kind, it is said to be constantly thieving, so that when anyone leaves
out cooked rice or other food, it takes it. It is difficult, however, to
reconcile such accounts with that of their bowelless condition; it is
thought to be a great misfortune to meet a kinòly. Another strange
creature is called Tòkan-tòngotra, or “Single foot,” because it is said
to have only one fore and one hind leg! It is so exceedingly swift that
no other creature has a chance of escaping it; it eats men and goes
about at night. Still another strange beast is called Siòna, which has
also, like the kinòly, something human about it. It is said to live away
from men, and when anyone goes through the woods and leaves his
rice, or his axe, these are taken by the siòna and conveyed to its
abode. When the woodmen go to sleep and leave a fire still burning
(for their custom is to leave a big log on the hearth, so that they may
be kept warm), then this creature comes and warms itself. Possibly
the habits of some of the larger lemurs have given rise to such
stories, aided by a good deal of imagination; and the tòkan-tòngotra
story probably comes from the herons or flamingoes, which have the
habit of standing on one leg when asleep.
In passing along the forest paths we frequently come across
examples of the curious ball-insect (Spherotherium sp.), of which
there are several species, at least six, in Madagascar. These insects,
which are wingless and many-footed, and are called, not very
elegantly, by the Malagasy Tainkìntana, or “Star-droppings,” have the
power of instantaneously rolling themselves into an almost perfect
sphere, which form they retain as long as any danger threatens
them, and no force short of pulling them to pieces can make them
unroll. The animal is formed of nine or ten segments, each with a
pair of legs and covered with a plate of armour; while the head and
tail are defended by larger plates, each of which fits into the other
and makes a more perfectly fitting suit of armour than was ever worn
by medieval knight. There are several species of these pretty and
curious creatures. The most common kind here is one which forms a
ball barely an inch in diameter and shining black in colour. Another,
more rarely seen in the interior open country, but common enough in
the upper belt of forest, is of a beautiful brown colour like russia
leather, and is quite double the size of the first-mentioned one. In
passing through the main forest in 1892, we came suddenly one day
to a part of the road which was so thickly covered by such a great
number of these creatures that our bearers could not avoid trampling
on them. These were of a bronze-green tint and belong to a third
species, and were quite three inches in length. Other species of
these Sphærotheria are found in Africa, Asia, Australia and some of
the neighbouring islands.
Another many-footed and wingless creature is common enough in
the upper forest, for we often found it on the upper verandah of the
house at Andràngalòaka; this is a shining black millipede, about a
foot in length, and half to three-quarters of an inch in thickness. It is
called by the natives Kòdikòdy, and its numerous reddish legs, not
far short of a thousand in number, have a curious effect of
successive waves as it moves along. Although not very inviting in
appearance, it is quite harmless and is a vegetable feeder. There is
another species, which is marked longitudinally with black and red
stripes.
More unpleasant by far is another many-legged CENTIPEDES
creature, the centipede, whose sting is said to be SCORPIONS
exceedingly painful, resembling the puncture of a hot
iron, and which is not uncommon in the interior as well as in the
forest. The mere touch of its minute claws, if it happens to crawl over
one, is said to produce pain and inflammation. I have turned small
centipedes out of the hole in a window-sill where the bolt would fall;
and I remember one morning, before getting out of bed, seeing a
pretty large one marching across our bedroom floor. Happily these,
which are among the few noxious creatures we have in Madagascar,
are not very common. Another unpleasant visitor is the scorpion,
which is rather apt to get into a house which has much stonework in
the basement; we frequently killed small ones about an inch long at
Antanànarìvo. Examples twice that size are found in the Vàvavàto
district; while on the shores of Bèmbatòka Bay (N.W.Co.) scorpions
five inches long occur, and Captain Owen says that they may be
found, one or more, under almost every stone. He states a curious
fact, if indeed it is one—viz. that the most destructive enemy to the
scorpion is the common mouse.[15]
[14]
“Ao ny àndro mamanala, “There are the chilly days,
Sakambino ao an-àla; Sustain them in the forest;
Raha mandeha mita rano, When they ford the rivers,
Mba hazòny sy tantano”; O uphold and guide them,”
etc. etc.
Ala, at the end of the first two lines, is the native word for “forest,”
and the native word translated here “chilly” is from the damp and
cold woods.
[15] Here I may notice that, in addition to the above-named
unpleasant inhabitants of Madagascar, we have had, within the
last eighteen years, a most unwelcome accession to the insect
pests, by the introduction of the chigoe, or “jigger,” which was
brought by the Senegalese black troops employed in the French
conquest of 1895. This minute flea does not jump, but runs over
one’s body, and burrows under the skin, chiefly in the feet, but
also sometimes in the hands, where it causes intolerable itching,
and, if not speedily removed with a needle, becomes in four or
five days full of eggs, and causes sores and inflammation. It is a
great pest to the Malagasy, the great majority of whom go
barefoot. But those who have boots and shoes on get no
exemption from the attacks of the jiggers.
CHAPTER XIII

FA U N A

W
HILE on the subject of noxious creatures, we remember that
one, if not more, of the spiders of Madagascar must be
included in the list. This is a small arachnid, about the size
and shape of a marble, shining glossy black in colour, except for a
small red spot on the fundament. It is greatly dreaded by the natives,
who believe its bite to be fatal, and it is probably so if cauterisation
and other remedies are not immediately applied. Dr Vinson, a
French naturalist, ascertained that this spider, called Mènavòdy by
the people, is closely allied to the malignant Latrodectus of Elba and
Corsica, whose bite is believed to be fatal, and also to another spider
found in Martinique, which is equally dangerous. People bitten by
this Madagascar spider scream out with pain at intervals of a minute
or two, as if it came on in paroxysms. I remember that one of our
servants when bringing one of these spiders to look at took care to
hold it at a very respectful distance from himself, at the end of a long
stick.
As we push through the bushes we break through SPIDERS
many spiders’ webs, and are struck by the
extraordinary shape of some of those whose snares we unwittingly
destroy by our passing along. Here is one, small and reddish in
colour, but much broader than it is long, each side projecting into a
long sharp spike—indeed it is spiky in several directions, and is
utterly unlike any other spider we know of. This is, I believe, a
species of Cærostris (C. stygiana?), and belongs to a genus of which
several species have names denoting their demoniacal shape and
colouring—e.g. avernalis, stygiana, etc.
As we stop to observe his geometric web, and his bizarre shape,
we see on the tree to which several of his main “guys” are fixed a
very different spider’s house and a very different spider from our
angular friend just mentioned. This creature is a much larger species
than the other, with jet-black legs and satiny dark grey abdomen as
large as a good-sized nut. He apparently hunts his prey, for he has
no net, but hides himself in an inverted cup-shaped house of strong
web. As I tap the top of this retreat he shams dead and tumbles
down into the grass, from which he will presently ascend as soon as
the enemy is clear off the ground.
Close by this hunting spider’s home we see the large web of a
third species, quite different from the other two. At first sight this
appears to be the same insect as the large Nephila, which is so
plentiful in Imèrina, in orchards and outside houses. A closer
inspection, however, shows that it is a different species from that
common large spider, for this one has a long filbert-shaped
abdomen, striped with brown lines, very different from the golden
and silvery markings of the more abundant species. It appears to be
strictly a forest spider and seems rather rare.
In rambling along the edge of one of the pretty rice-valleys north of
Ambòhimànga, I came across a species I had not met with before.
This was of medium size, but was striped in transverse lines of white
and black across the abdomen, so as to give it a zebra-like
appearance. The under side was almost white; altogether it is a
handsome species, and is probably still undescribed scientifically. It
makes a geometrical web, and, like several other Madagascar
spiders, puts the web into rapid vibration if it is disturbed. Some
species draw up their legs close to the body when lying in wait in the
centre of their web, so that they too resemble a small lump of earth
or a stone. Is not this also done as a disguise? It seems to me highly
probable. Other species have the habit of stretching out their legs in
couples, so as to seem almost as if they had only four or six legs
instead of eight, and thus appear to mimic insects. Is this also
intended to hide their predaceous character?
A traveller through the Tanòsy country, south-east coast, speaks of
the uncanny aspect of one of the villages in which he stayed; and he
says that what increased his impression of it, as like a town of
wicked enchanters, was that all the houses were festooned and
closely linked together overhead by tangled masses of gigantic
spiders’ webs, amongst which lay in wait monstrous black spiders.
Some of the coast villages, he says, were almost completely roofed
in by these great webs. Spaces of quite thirty feet have been
observed spanned by the lines of the nephila mentioned in a former
chapter; and I have noticed that the angles and outer spaces of its
great web are frequently filled up by the minute geometric webs of
smaller species. These lesser fry appear to be tolerated, if not
encouraged, by their giant neighbour, as they probably catch what
would be insignificant to her, and very likely clear her web of what
she rejects; and so they all live together in harmony in a small
colony.
Looking about in the undergrowth for wild flowers PROTECTIVE
and fruit, and happening to rub against the stem of RESEMBLANCE
one of the bushes, a small rough roundish ball falls off on to the
ground; this appears exactly like a bit of round wrinkled bark, but on
watching for a minute or two, it develops four pairs of legs, and runs
nimbly away under cover, revealing itself as a spider, with a
marvellous protective resemblance to its surroundings. Unless the
creature actually moves, it is impossible to detect it, it is so exactly
like a knobby bit of the brown bark.
Protective resemblance in quite a different style appears in a small
spider, perfectly white in colour—thorax, legs and abdomen—which
scuttles out of the coralla of certain white flowers when these are
examined or shaken. This also, unless it moves, is all but invisible;
and there can be no doubt that it is thus enabled to catch the many
small flies which are attracted by the honey and fragrance of the
flowers. A larger and green spider, a handsome species, with a long
oval abdomen striped with red, probably also a hunter, thanks to its
close resemblance to green leaves and the pale reddish veining
seen on many leaves, by which it is thus protected from observation
until it can pounce upon its prey. This is one species of the many
spiders which are caught by some of the solitary wasps, as
described in Chapter VII.
As we notice these curious disguises in spiders, as well as in
numbers of other living creatures, we are reminded of the old
nursery tales and fables of the gift of invisibility supposed to be
conferred by certain plants, or by certain charms or ceremonies.
With these spiders, as well as in many other creatures, some lower,
and others much higher, than them in organisation, this power of
becoming at will unseen, even under the closest observation, is no
fable, but a veritable fact. There is a curious habit which I have
observed in several species of Malagasy spiders which is apparently
also used for protection. If they are disturbed, or if their web is
shaken, they immediately throw themselves into a state of violent
vibration, so that the eye cannot follow them; and this rapid motion is
continued for two or three minutes, until the supposed danger has
passed away. It would seem as if this must be done to confuse a
possible enemy intending to attack them.
Besides the red-spot spider, there is another kind VENOMOUS
called by the natives Fòka; this is rather common in SPIDERS
gardens and is extremely like a small crab, with a lozenge-shaped
abdomen; it is covered with tubercles, and its legs are roughened,
like those of a crustacean. Its bite is followed by swelling, which
spreads from the wounded part through the whole body. This
dangerous spider’s bite is said to be often fatal. There is another
spider, apparently a species of Mygale, called by the people
Tàrabìby, found fifty to sixty miles west of the capital, whose bite is
also said to be dangerous, if not actually fatal. It appears to be a
trap-door species. Besides this one, another species of trap-door
spider is also said to be found in Imèrina, but I have not seen a
specimen myself; it is said to leave the door of its dwelling open.
The illustration given herewith will give a better idea than any mere
description can of the strange shapes of many Madagascar spiders.
The largest figure shows an Epeira of extraordinary shape; it will be
seen that the abdomen is like a set of three cones, fixed into one
another and terminated by a sharpish point. A still more bizarre
figure is presented by Epeira mitralis, as it crouches, fixed close to a
branch or twig; whether viewed from the back or front or side, it is
equally “uncanny” in its appearance. Then, again, the two Gastera-
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!

textbookfull.com

You might also like