Fundamentals Of Python First Programs MindTap Course List 3rd Edition Kenneth A. Lambert All Chapters Instant Download
Fundamentals Of Python First Programs MindTap Course List 3rd Edition Kenneth A. Lambert All Chapters Instant Download
https://ebookgate.com
https://ebookgate.com/product/fundamentals-of-
python-first-programs-mindtap-course-list-3rd-
edition-kenneth-a-lambert/
https://ebookgate.com/product/writing-ten-core-concepts-w-
mla9e-updates-mindtap-course-list-3rd-edition-robert-p-yagelski/
ebookgate.com
https://ebookgate.com/product/python-programming-for-teens-1st-
edition-kenneth-a-lambert/
ebookgate.com
https://ebookgate.com/product/the-fundamentals-of-drawing-portraits-a-
practical-and-inspirational-course-barrington-barber/
ebookgate.com
https://ebookgate.com/product/physiology-and-nutrition-for-amateur-
wrestling-first-edition-lambert/
ebookgate.com
A First Course in Topology John Mccleary
https://ebookgate.com/product/a-first-course-in-topology-john-
mccleary/
ebookgate.com
https://ebookgate.com/product/python-crash-course-a-hands-on-project-
based-introduction-to-programming-1st-edition-eric-matthes/
ebookgate.com
https://ebookgate.com/product/the-history-of-mathematics-a-brief-
course-3rd-ed-2013-3rd-edition-roger-l-cooke/
ebookgate.com
https://ebookgate.com/product/fundamentals-of-geomorphology-3rd-
edition-routledge-fundamentals-of-physical-geography-richard-huggett/
ebookgate.com
https://ebookgate.com/product/a-first-course-in-loop-quantum-gravity-
gambini/
ebookgate.com
Fundamentals
of Python First
Programs Third Edition
Kenneth A. Lambert
Fundamentals
of Python
First Programs
Third Edition
Kenneth A. Lambert
Copyright 2024 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 2024 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Fundamentals of Python: First Programs, © 2024 Cengage Learning, Inc. ALL RIGHTS RESERVED.
Third Edition Previous edition(s): © 2015, © 2012.
Kenneth A. Lambert WCN: 02-300
No part of this work covered by the copyright herein may be reproduced
or distributed in any form or by any means, except as permitted by U.S.
SVP, Product: Cheryl Costantini copyright law, without the prior written permission of the copyright owner.
VP, Product: Thais Alencar Unless otherwise noted, all content is Copyright © Cengage Learning, Inc.
Portfolio Product Director: Rita Lombard The names of all products mentioned herein are used for identification
purposes only and may be trademarks or registered trademarks of their
Portfolio Product Manager: Tran Pham respective owners. Cengage Learning disclaims any affiliation, association,
connection with, sponsorship, or endorsement by such owners.
Product Assistant: Anh Nguyen
VP, Product Marketing: Jason Sakos Library of Congress Control Number: 2023904384
Cover Image Source: Armagadon/shutterstock.com Cengage is a leading provider of customized learning solutions.
Our employees reside in nearly 40 different countries and serve digital
learners in 165 countries around the world. Find your local representative at:
www.cengage.com.
Copyright 2024 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.
Brief Contents
About the Authorxi
Prefacexiii
Chapter 1 Introduction����������������������������������������������������������������������������������������������������� 1
Glossary439
Index453
iii
Copyright 2024 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
About the Author xi
Preface xiii
Chapter 1
Introduction 1
1.1 T
wo Fundamental Ideas of Personal Computing and Networks (1975–1990) 12
Computer Science: Algorithms and Consultation, Communication, and E-Commerce
Information Processing 1 (1990–2000) 14
Algorithms 2 Mobile Applications and Ubiquitous Computing
Information Processing 3 (2000–present) 15
1.2 T
he Structure of a Modern 1.4 G
etting Started with Python
Computer System 4 Programming16
Computer Hardware 4 Running Code in the Interactive Shell 16
Chapter 2
Software Development, Data Types, and Expressions 27
2.1 T
he Software Development 2.3 N
umeric Data Types and
Process27 Character Sets 37
2.2 S
trings, Assignment, and Integers 37
Comments32 Floating-Point Numbers 37
Data Types 33 Character Sets 38
String Literals 33 2.4 Expressions 39
Escape Sequences 34 Arithmetic Expressions 39
String Concatenation 34 Mixed-Mode Arithmetic and Type Conversions 41
Variables and the Assignment Statement 35
2.5 Using Functions and Modules 43
Program Comments and Docstrings 36
Calling Functions: Arguments and Return Values 43
iv
Copyright 2024 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 v
Chapter 3
Loops and Selection Statements 53
3.1 Definite Iteration: The for Loop 53 Logical Operators and Compound Boolean
Expressions 68
Executing a Statement a Given Number of Times 54
Short-Circuit Evaluation 70
Count-Controlled Loops 55
Testing Selection Statements 70
Augmented Assignment 56
Loop Errors: Off-by-One Error 56 3.4 C
onditional Iteration: The while
Traversing the Contents of a Data Sequence 57 Loop71
Specifying the Steps in the Range 57 The Structure and Behavior of a while Loop 72
Chapter 4
Strings and Text Files 87
4.1 A
ccessing Characters and Converting Binary to Decimal 94
Substrings in Strings 87 Converting Decimal to Binary 95
The Structure of Strings 87 Conversion Shortcuts 95
The Subscript Operator 88 Octal and Hexadecimal Numbers 96
Slicing for Substrings 89 4.4 String Methods 97
Testing for a Substring with in Operator 90
4.5 Text Files 100
4.2 Data Encryption 91 Text Files and Their Format 100
4.3 Strings and Number Systems 93 Writing Text to a File 101
The Positional System for Representing Writing Numbers to a File 101
Numbers 93 Reading Text from a File 101
Copyright 2024 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.
vi Contents
Chapter 5
Lists and Dictionaries 115
5.1 Lists 115 The return Statement 127
List Literals and Basic Operators 116 Boolean Functions 127
Replacing an Element in a List 118 Defining a main Function 127
List Methods for Inserting and Removing 5.3 Dictionaries 132
Elements 119
Dictionary Literals 132
Searching a List 120
Adding Keys and Replacing Values 132
Sorting a List 121
Accessing Values 133
Mutator Methods and the Value None 121
Removing Keys 133
Aliasing and Side Effects 122
Traversing a Dictionary 133
Equality: Object Identity and Structural
Example: The Hexadecimal System Revisited 134
Equivalence 123
Example: Finding the Mode of a List
Example: Using a List to Find the Median of
of Values 135
a Set of Numbers 123
Summary 141
Tuples 124
Key Terms 142
5.2 Defining Simple Functions 126 Review Questions 142
The Syntax of Simple Function Definitions 126 Programming Exercises 143
Parameters and Arguments 127 Debugging Exercise 144
Chapter 6
Design with Functions 145
6.1 A
Quick Review of What Functions 6.3 M
anaging a Program’s
Are and How They Work 145 Namespace156
Functions as Abstraction Mechanisms 146 Module Variables, Parameters, and
Functions Eliminate Redundancy 146 Temporary Variables 156
Copyright 2024 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 vii
Chapter 7
Design with Recursion 165
7.1 Design with Recursive Functions 165 Mapping 180
Defining a Recursive Function 166 Filtering 181
Recursive Algorithms 167 Reducing 181
Tracing a Recursive Function 167 Using lambda to Create Anonymous Functions 182
Using Recursive Definitions to Construct Creating Jump Tables 182
Recursive Functions 168 Summary 185
Recursion in Sentence Structure 168 Key Terms 185
Infinite Recursion 170 Review Questions 186
The Costs and Benefits of Recursion 170 Programming Exercises 187
7.2 Higher-Order Functions 179 Debugging Exercise 188
Functions as First-Class Data Objects 179
Chapter 8
Simple Graphics and Image Processing 189
8.1 Simple Graphics 189 Image-Manipulation Operations 205
Overview of Turtle Graphics 190 The Properties of Images 205
Turtle Operations 190 The images Module 205
Setting Up a turtle.cfg File and Running IDLE 192 A Loop Pattern for Traversing a Grid 208
Object Instantiation and the turtle Module 192 A Word on Tuples 209
Drawing Two-Dimensional Shapes 194 Converting an Image to Black and White 209
Examining an Object’s Attributes 195 Converting an Image to Grayscale 210
Manipulating a Turtle’s Screen 196 Copying an Image 211
Taking a Random Walk 196 Blurring an Image 212
Colors and the RGB System 197 Edge Detection 213
Example: Filling Radial Patterns with Random Reducing the Image Size 214
Colors 198 Summary 216
8.2 Image Processing 203 Key Terms 217
Analog and Digital Information 204 Review Questions 217
Sampling and Digitizing Images 204 Programming Exercises 218
Image File Formats 204 Debugging Exercise 221
Chapter 9
Graphical User Interfaces 223
9.1 T
he Behavior of Terminal-Based 9.2 C
oding Simple GUI-Based
Programs and GUI-Based Programs226
Programs224 A Simple “Hello World” Program 227
The Terminal-Based Version 224 A Template for All GUI Programs 228
The GUI-Based Version 225 The Syntax of Class and Method Definitions 228
Event-Driven Programming 226 Subclassing and Inheritance as Abstraction
Mechanisms 229
Copyright 2024 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.
viii Contents
9.3 W
indows and Window Using Nested Frames to Organize
Components229 Components 247
Windows and Their Attributes 230 Multiline Text Areas 248
Window Layout 230 File Dialogs 250
Types of Window Components and Their Obtaining Input with Prompter Boxes 252
Attributes 232 Check Buttons 253
Displaying Images 233 Radio Buttons 254
9.4 C
ommand Buttons and Keyboard Events 256
Responding to Events 235 Working with Colors 256
9.5 I nput and Output with Entry Using a Color Chooser 258
Fields237 Summary 260
Text Fields 237 Key Terms 260
Integer and Float Fields for Numeric Data 238 Review Questions 261
9.6 D
efining and Using Instance Programming Exercises 262
Variables240 Debugging Exercise 263
9.7 O
ther Useful GUI Resources 246
Chapter 10
Design with Classes 265
10.1 G
etting Inside Objects and Input of Objects and the try-except
Classes266 Statement 289
Rational Number Arithmetic and Operator Example 2: The Dealer and a Player in the
Overloading 281 Game of Blackjack 308
Equality and the __eq__ Method 282 The Costs and Benefits of Object-Oriented
Programming 312
The __repr__ Method for Printing an Object
in IDLE 283 Summary 315
Savings Accounts and Class Variables 284 Key Terms 316
Putting the Accounts into a Bank 286 Review Questions 317
Using pickle for Permanent Storage Programming Exercises 318
of Objects 288 Debugging Exercise 320
Copyright 2024 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 ix
Chapter 11
Data Analysis and Visualization 321
11.1 S
ome Basic Functions for 11.3 W
orking with More Complex
Analyzing a Data Set 322 Data Sets 343
Computing the Maximum, Minimum, and Mean 323 Creating a Data Set with pandas 344
Computing the Median 323 Visualizing Data with pandas and
Computing the Mode and Modes 324 matplotlib.pyplot 344
Computing the Standard Deviation 325 Accessing Columns and Rows in a Data Frame 345
Using the NumPy Library 326 Creating a Data Frame from a CSV File 346
Cleaning the Data in a Data Frame 347
11.2 Visualizing a Data Set 333
Accessing Other Attributes of a Data Frame 348
Pie Charts 335
Summary 354
Bar Charts 337
Key Terms 354
Scatter Plots 339
Review Questions 354
Line Plots 340
Programming Exercises 355
Histograms 342
Chapter 12
Multithreading, Networks, and Client/Server Programming 357
12.1 Threads and Processes 357 12.3 N
etworks, Clients, and
Threads 358 Servers374
Sleeping Threads 360 IP Addresses 374
Producer, Consumer, and Synchronization 362 Ports, Servers, and Clients 375
Sockets and a Day/Time Client Script 375
12.2 T
he Readers and Writers
Problem368 A Day/Time Server Script 377
Implementing the Interface of the SharedCell Handling Multiple Clients Concurrently 380
Class 370 Summary 388
Implementing the Helper Methods of the Key Terms 389
SharedCell Class 371 Review Questions 389
Testing the SharedCell Class with Programming Exercises 390
a Counter Object 372
Debugging Exercise 392
Defining a Thread-Safe Class 373
Chapter 13
Searching, Sorting, and Complexity Analysis 393
13.1 M
easuring the Efficiency of 13.2 Complexity Analysis 398
Algorithms394 Orders of Complexity 398
Measuring the Run Time of an Algorithm 394 Big-O Notation 400
Counting Instructions 396
Copyright 2024 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.
x Contents
Appendix A
Python Resources 429
Appendix B
Installing the images and breezypythongui Libraries 431
Appendix C
The API for Image Processing 433
Appendix D
Transition from Python to Java and C++ 435
Appendix E
Suggestions for Further Reading 437
Glossary439
Index453
Copyright 2024 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.
About the Author
Kenneth A. Lambert is Professor of Computer Science Emeritus at Washington and Lee University. He taught
introductory programming courses for 37 years and has been an active researcher in computer science educa-
tion. Lambert has co-authored a series of introductory C++ textbooks with Douglas Nance and Thomas Naps
and a series of introductory Java textbooks with Martin Osborne. He is the author of Python textbooks for CS1
and CS2 college-level courses and a Python textbook for teens. He is also the co-creator of the BreezySwing
framework and is the creator of the breezypythongui framework.
Dedication
To my grandchildren—Lucy, Wyatt, Cuba, and Van
Kenneth A. Lambert
Lexington, VA
xi
Copyright 2024 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 2024 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
“Everyone should learn how to code.” That’s my favorite quote from Suzanne Keen, formerly the Thomas
Broadus Professor of English and Dean of the College at Washington and Lee University, where I have taught
computer science for more than 30 years. The quote also states the reason why I wrote the first and second
editions of Fundamentals of Python: First Programs, and why I now offer you this third edition. The book is
intended for an introductory course in programming and problem solving. It covers the material taught in a
typical Computer Science 1 (CS1) course at the undergraduate or high school level.
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 introductory level. Today’s students
learn a bit of programming and problem solving and are then expected to move quickly into topics like software
development, complexity analysis, and data structures that 35 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 programming languages such as
xiii
Copyright 2024 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.
xiv Preface
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 language and more time learning to solve interesting problems.
• Python has safe semantics. Any expression or statement whose meaning violates the definition of the language
produces an error message.
• Python scales well. It is very easy for beginners to write simple programs in Python. Python also includes all
of the advanced features of a modern 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 interpreter’s prompts to allow the
programmer to try out experimental code and receive immediate feedback. Longer code segments can then be
composed and saved in script files to be loaded and run as modules or standalone applications.
• Python is general purpose. In today’s context, this means that the language includes resources for
contemporary applications, including media 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.
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.
Chapter 1 introduces computer science by focusing on two fundamental ideas, algorithms and information pro-
cessing. 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 interesting applications. Chapter 5 also introduces simple
function definitions as a way of organizing algorithmic code.
Chapter 6 explores the technique and benefits of procedural abstraction with function definitions. Top-down design
and stepwise refinement with functions are examined as means of structuring code to solve complex problems. Details
of namespace organization (parameters, temporary variables, and module variables) and communication among soft-
ware components are discussed.
Chapter 7 examines recursive design with functions. A section on functional programming with higher-order func-
tions shows how to exploit functional design patterns to simplify solutions.
Copyright 2024 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 xv
Chapter 8 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. These are areas in which object-based programming is particularly useful.
Chapter 9 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
chapter explores the creation and layout of GUI components, 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
textbook: students learn that the easiest way to define a new class is to customize an existing class using subclassing
and inheritance.
Chapter 10 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 inte-
grated into more realistic applications to show how object-oriented software components can be used to build complex
systems. Emphasis is on designing appropriate interfaces for classes that exploit polymorphism.
Chapter 11 introduces tools and techniques for performing data analysis, a fast-growing application area of com-
puter science. Topics include the acquisition and cleaning of data sets, applying functions to determine relationships
among data, and deploying graphs, plots, and charts to visualize these relationships.
Chapter 12 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. This chapter introduces multithreaded programs and the construction of simple network-based client/
server applications.
Chapter 13 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 algorithms and data structures, using search and sort algorithms as examples.
• A new chapter (Chapter 7) on design with recursion. This chapter incorporates and expands on material on
recursive functions and higher-order functions from Chapter 6 of the second edition.
• A new chapter (Chapter 11) on data analysis and visualization. This chapter introduces tools and techniques
for acquiring data sets, cleaning them, and applying functions to them to determine relationships which can be
visualized in plots, charts, and graphs.
• Updated coverage of the history of computing in Chapter 1.
• New fail-safe programming sections added to most chapters to demonstrate best practices for programming
securely.
• New list of key terms in each chapter.
• Updated end-of-chapter review questions and programming exercises.
• End-of-chapter programming exercises mapped to the learning objectives for each chapter.
• New debugging exercises in each chapter provide examples of challenging programming errors and give you
experience in diagnosing and correcting them.
• Several new case studies as well as new or updated programming exercises.
• Text revisions throughout with a focus on readability.
Copyright 2024 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.
xvi Preface
• Chapter Objectives: Each chapter begins with a set of learning objectives which describe the skills and
concepts you will acquire from a careful reading of the chapter.
• Chapter Summary: Each chapter ends with a summary of the major concepts covered in the chapter.
• Key Terms: When a technical term is introduced in the text, it appears in boldface. The list of terms appears
after the chapter summary. Definitions of the key terms are provided in the glossary.
Exercise
Exercises: Most major sections of each chapter end with exercise questions that reinforce the reading by asking
basic questions about the material in the section.
Case Study
Case Studies: The Case Studies present complete Python programs ranging from the simple to the
substantial. To emphasize the importance and usefulness of the software development life cycle, case
studies are discussed in the 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 programming exercises.
Fail-Safe Programming
Fail-Safe Programming: Fail-Safe Programming sections include a discussion of ways to make a program
detect and respond gracefully to disturbances in its runtime environment.
Copyright 2024 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 xvii
Review Questions
Review Questions: Multiple-choice review questions allow you to revisit the concepts presented in each
chapter.
Programming Exercises
Programming Exercises: Each chapter ends with a set of programming projects of varying difficulty. Each
programming exercise is mapped to one or more relevant chapter learning objectives and gives you the
opportunity to design and implement a complete program that utilizes major concepts presented in that
chapter.
Debugging Exercises
Debugging Exercises: Debugging exercises illustrate a typical program error with suggestions for repairing it.
• A software toolkit for image processing: This book comes with an open-source Python toolkit for the easy
image processing discussed in Chapter 8. The toolkit can be obtained with the ancillaries at www.cengage.com
or at https://kennethalambert.com/python/
• A software toolkit for GUI programming: This book comes with an open-source Python toolkit for the easy GUI
programming introduced in Chapter 9. The toolkit can be obtained with the ancillaries at www.cengage.com or
at https://kennethalambert.com/breezypythongui/
• Appendices: Five appendices include information on obtaining Python resources, installing the toolkits, using
the toolkits’ interfaces, and suggestions for further reading.
• Glossary: Definitions of key terms are collected in a glossary.
Copyright 2024 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.
xviii Preface
materials seek to affirm the fullness of human diversity with respect to ability, language, culture, gender, age, socio-
economics, and other forms of human difference that students may bring to the classroom.
Across the computing industry, standard coding language, such as “Master” and “Slave” is being retired in favor of lan-
guage that is more inclusive, such as “Supervisor/Worker,” “Primary/Replica,” or “Leader/Follower.” At this time, different
software development and social media companies are adopting their own replacement language and currently there is no
shared standard. In addition, the terms “Master” and “Slave” remain deeply embedded in legacy code and understanding
this terminology remains necessary for new programmers. When required for understanding, Cengage will introduce the
non-inclusive term in the first instance but will then provide an appropriate replacement terminology for the remainder of
the discussion or example. We appreciate your feedback as we work to make our products more inclusive for all.
For more information about Cengage’s commitment to inclusivity and diversity, please visit https://www.cengage
.com/inclusion-diversity/
Course Solutions
Online Learning Platform: MindTap
Today’s leading online learning platform, MindTap for Fundamentals of Python, Third Edition provides complete con-
trol to craft a personalized, engaging learning experience that challenges students, builds confidence, and elevates
performance.
MindTap introduces students to core concepts from the beginning of the course, using a simplified learning path
that progresses from understanding to application and delivers access to eTextbooks, study tools, interactive media,
auto-graded assessments, and performance analytics.
MindTap activities for Fundamentals of Python: First Programs are designed to help students build the skills needed
in today’s workforce. Research shows employers seek critical thinkers, troubleshooters, and creative problem-solvers
to stay relevant in our fast-paced, technology-driven world. MindTap achieves this with assignments and activities
that provide hands-on practice and real-life relevance. Students are guided through assignments that reinforce basic
knowledge and understanding before moving on to more challenging problems.
All MindTap activities and assignments are tied to defined chapter learning objectives. Hands-on coding labs pro-
vide real-life application and practice. Readings and dynamic visualizations support the lecture, while a post-course
assessment measures exactly how 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. The content and learning path
can be used as provided, customized directly in the MindTap platform, or integrated into the Learning Management
System (LMS) to meet the needs of a particular course . Instructors can control what students see and when they see
it. Learn more at https://www.cengage.com/mindtap.
In addition to the readings, the MindTap for Fundamentals of Python: First Programs, Third Edition includes the following:
• Coding labs. These supplemental assignments provide real-world application and encourage students to
practice new programming concepts in a complete online IDE. New and improved Guided Feedback provides
personalized and immediate feedback to students as they proceed through their coding assignments so that
they can understand and correct errors in their code.
• Gradeable assessments and activities. All assessments and activities from the readings are available as
gradeable assignments within MindTap, including Exercises and Review Questions.
• Video quizzes. These graded assessments provide a visual explanation of foundational programming concepts
that can be applied across multiple languages. Questions accompany each video to confirm understanding of
new material.
Copyright 2024 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.
Another random document with
no related content on Scribd:
The Project Gutenberg eBook of The Germ
and mystery
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
BY
ROBERT EASTERLEY and JOHN WILBRAHAM.
“His . . . . . . . .
Prosequitur dictis portaque emittit eburna.”
MELBOURNE:
MELVILLE, MULLEN, & SLADE.
LONDON: HUTCHINSON & CO.
1892.
[All rights reserved.]
v
TABLE OF CONTENTS.
———♦———
PAGE
Preliminary . . . . . . . . . . . . 1
CHAPTER I.
Disappearances . . . . . . . . . . . 6
CHAPTER II.
The Red Sickness . . . . . . . . . . 13
CHAPTER III.
At Sea . . . . . . . . . . . . . 26
CHAPTER IV.
Overland . . . . . . . . . . . . . 36
CHAPTER V.
Among the Blacks . . . . . . . . . . 58
CHAPTER VI.
vi Left Alone . . . . . . . . . . . . 86
CHAPTER VII.
The Cars . . . . . . . . . . . . . 97
CHAPTER VIII.
Signor Davelli . . . . . . . . . . . 131
CHAPTER IX.
The Seed Beds . . . . . . . . . . . 167
CHAPTER X.
Leäfar . . . . . . . . . . . . . . 202
CHAPTER XI.
Escape . . . . . . . . . . . . . 233
Conclusion . . . . . . . . . . . . 267
1
PRELIMINARY.
It was delicious weather, warm enough for light silk coats in the
daytime, and cold enough for two pairs of blankets at night. We had
riding and sea-bathing to our hearts’ content, and even a rough kind
of yachting and fishing. The ocean was before us—we heard its
thunder night and day; and the lakes were behind us, stretching
away to the promontory which the Mitchell cuts in two, and thence
to the mouth of the Latrobe, which is the highway to Sale. Three
times a week a coach passed our door, bound for the Snowy River
and the more savage regions beyond. Any day for a few shillings we
could be driven to Lake Tyers, to spend a day amidst scenery almost
comparable with the incomparable Hawkesbury. Last of all, if we
grew tired of the bell-birds and the gum-trees and the roar of the
ocean, we were within a day’s journey of Melbourne by lake and
river and rail.
It was our custom to be out all day, but home early and early to
bed. We used to take our meals in a low long room which was well
aired but poorly lighted, whether by day or night. And here, when
tea was over and the womenkind had retired, we smoked, whenever,
3
as often happened, the evening was cold enough to make a shelter
desirable; smoked and chatted. There was light enough to see the
smoke of your pipe and the faces of those near you; but if you were
listening to the chatter of a group in the other end of the room the
faces of the speakers were so indistinct as often to give a startling
challenge to your imagination if you had one, and if it was
accustomed to take the bit in its teeth. I sometimes caught myself
partly listening to a story-teller in the other end of the room and
partly fashioning a face out of his dimly seen features, which quite
belied the honest fellow’s real countenance when the flash of a
pipelight or a shifted lamp revealed it more fully.
Jack and I were more of listeners than talkers, and we were usually
amongst the earliest who retired. But one evening there was a good
deal of talk about the new gold-field in the north-west, and a keen-
looking bushman who seemed to have just returned from the place
began to describe its whereabouts. Then I listened attentively, and
at one point in his talk, I started and looked over at Jack, and I saw
that he was already looking at me. I got up and left the room
without a sign to him, but I knew that he would follow me, and he
did. It was bright moonlight, and when we met outside we strolled
4
down to the beach together. It was a wide, long, and lonely beach,
lonely to the very last degree, and it was divided from the house by
a belt of scrub near a mile wide. We said not a word to one another
till we got quite near the sea. Then I turned round and looked Jack
in the face and said, “Why, man, it must have been quite near the
place.”
“No,” said he, “it may have been fifty miles or more away, their
knowledge is loose, and their description looser, but it must be
somewhere in the neighbourhood, and I suppose they are sure to
find it.”
“That might be,” said he, “if they believed you; but they would not
believe you, they would think you were simply romancing.”
“Well,” said I, “let it be a joint concern between you and me, and I’ll
do my best.”
Then we lit our pipes and walked home, and settled the matter in a
very few words on the way. I was to write, but all I should write was
to be read over to Jack, who should correct and supplement it from
his own memory. And no account of anything which was witnessed
by both of us was to stand finally unless it was fully vouched for by
the memory of both. Thus for any part of the narrative which would
concern one of us only that one should be alone responsible, but for
all of it in which we were both concerned there should be a joint
responsibility.
When I was quite a boy, scarce yet fifteen years old, I happened to
be living in a parish on the Welsh coast, which I will here call
Penruddock. There were some bold hills inland and some very wild
and rugged cliffs along the coast. But there was also a well-sheltered
beach and a little pier where some small fishing vessels often lay.
Penruddock was not yet reached by rail, but forty miles of a splendid
7
road, through very fine scenery, took you to a railway station. And
this journey was made by a well-appointed coach on five days of
every week.
There was one such story which was constantly reproduced under
various forms. Sometimes it was said to have happened in the last
generation; sometimes as far back as the civil wars, of which,
strange to say, a lively traditional recollection still remained in the
neighbourhood; and sometimes it seemed to have been handed
down from prehistoric times, and was associated with tales of
enchantment
8
and fairyland. In such stories the central event was
always the unaccountable disappearance of some person, and the
character of the person disappearing always presented certain
unvarying features. He was always bold and fascinating, and yet in
some way or other very repulsive. And when you tried to find out
why, some sort of inhumanity was always indicated, some
unconscious lack of sympathy which was revolting in a high degree
or even monstrous. The stories had one other feature in common, of
which I will tell you presently.
I went about with him a good deal at one time on fishing and
shooting excursions and made myself useful to him, and except that
he was rather cruel to dogs and cats, and had a nasty habit of
frightening children, I do not know that I noticed anything particular
about him. Not, at least, until one day of which I am going to tell
you. James Redpath and I were coming back together to
Penruddock, and we called at a cottage about two miles from the
village. Here we found a little boy of about four years old, who had
been visiting at the cottage and whom they wanted to send home.
They asked us to take charge of him and we did so. On the way
home the little boy’s shoe was found to have a nail or a peg in it that
hurt his foot, and we were quite unable to get it out. It was nothing,
however, to James Redpath to carry him, and so he took him in his
arms. The little boy shrank and whimpered as he did so. James had
under
10
his arm some parts of a fishing-rod and one of these came in
contact with the little boy’s leg and scratched it rather severely so as
to make him cry. I took it away and we went on. I was walking a
little behind Redpath, and as I walked I saw him deliberately take
another joint of the rod, put it in the same place and then watch the
little boy’s face as it came in contact with the wire, and as the child
cried out I saw quite a malignant expression of pleasure pass over
James’s face. The thing was done in a moment and it was over in a
moment; but I felt as if I should like to have killed him if I dared. I
always dreaded and shunned him, more or less, afterwards, and I
began from that date to associate him with the inhuman heroes of
my Welsh stories.
I don’t think that I should ever have got over the dislike of him
which I then conceived, but I saw the last of him, at least
Penruddock saw the last of him, about three months later. I had
been sitting looking over the sea between the pier and the cliffs and
trying to catch a glimpse of the Wicklow Mountains which were
sometimes to be seen from that point. Just then James Redpath
came up from the beach beyond the pier, and passing me with a
brief “good morning,” went away inland, leaving the cliffs behind
11
him. I don’t know how long I lay there, it might be two hours or
more, and I think I slept a little. But I suddenly started up to find it
high day and past noon, and I began to think of looking for some
shelter. There was not a cloud visible, but nevertheless two shadows
like, or something like, the shadows of clouds lay near me on the
ground. What they were the shadows of I could not tell, and I was
about to get up to see, for there was nothing to cast such a shadow
within the range of my sight as I lay. Just then one of the shadows
came down over me and seemed to stand for a moment between
me and the sun. It had a well-defined shape, much too well defined
for a cloud. I thought as I looked that it was just such a shadow as
might be cast by a yawl-built boat lying on the body of a large
wheelbarrow. Then the two shadows seemed to move together and
to move very quickly. I had just noticed that they were exactly like
one another when the next moment they passed out of my sight.
As I thought it all over and tried to persuade myself that I had been
dreaming I suddenly remembered that James Redpath had passed
by a few hours before, and as suddenly I came to the conclusion
that I should never see him again. And certainly he never was again
seen, dead or alive, anywhere in Wales or England. His father, and
his uncle, and their families, continued to live about Penruddock, but
Penruddock never knew James Redpath any more. Whether I myself
saw him again or not is more than I can say with absolute certainty.
You shall know as much as I know about it if you hear my story to
the end.
13
CHAPTER II.
THE RED SICKNESS.
But a public calamity just then befell Penruddock which made men
forget James Redpath’s disappearance. A pestilence broke out in the
place of which nobody knew either the nature or the source. It
seemed to spring up in the place. At least, all efforts to trace it were
unsuccessful. The first two or three cases were attributed to some
inflammatory cold, but it soon became clear that there were specific
features about it, that they were quite unfamiliar, that the disease
was extremely dangerous to life and highly infectious.
Then a panic set in, and I believe that the disease would soon have
been propagated all over England and farther, if it had not been for
the zeal and ability of two young physicians who happened very
fortunately to be living in the village just then. Their names were
Leopold and Furniss. I forget if I ever knew their Christian names.
We used to call them Doctor Leopold and Doctor Furniss. They had
finished their studies for some little time, but they found it advisable
15
on the score of health to take a longish holiday before commencing
practice, and they were spending part of their holiday at
Penruddock. They were just about to leave us when the disease I
am telling you of broke out.
The first case occurred in a valley about two miles from the village.
In this valley there were several cottages inhabited mostly by farm
labourers and artisans. These cottages lay one after another in the
direction of the rising ground which separated the valley from
Penruddock. Then there were no houses for a considerable space.
Then, just over the hill, there was another and yet another. The
disease had made its way gradually up the hill from one cottage to
another, day after day a fresh case appearing. Then there had been
no new cases for four days, but on the fifth day a new case
appeared in the cottage just over the brow of the hill. And when this
became known, also that every case (there had now been eleven)
had hitherto been fatal, serious alarm arose. Then, too, the disease
became known as the “red sickness.” This name was due to a
discoloration which set in on the shoulders, neck, and forehead very
shortly after seizure.
How the two doctors, as we called them, became armed with the
needful powers I do not know. They certainly contrived to obtain
some
16
sort of legal authority, but I think that they acted in great
measure on their own responsibility.
The excitement and terror in Penruddock were very great. All but the
most necessary business was suspended, and of social intercourse
during the panic there was next to none. Ten cases in all were
treated by the physicians, and four of these recovered. The last two
cases were three or four days apart, but they were no less malignant
in character: the very last case was one of the fatal ones. I learned
nothing of the treatment; but the means used to prevent the disease
spreading, besides the strict quarantine, were chiefly fire and lime.
Everything about the sick was passed through the fire, and of these
everything that the fire would destroy was destroyed. Lime, which
abounded in the valley, was largely used.
A month after the last case the two physicians declared the
quarantine at an end, and a month later all fear of the disease had
ceased. And then the people of the village began to think of
consoling themselves for the dull and uncomfortable time they had
had, and of doing some honour to the two visitors who had served
the village so well. With this double purpose in view a picnic on a
large
18
scale was organized, and there was plenty of eating and
drinking and speech-making and dancing, all of which I pass over.
But at that picnic I heard a conversation which made a very powerful
impression on me then, and which often has seemed to provide a
bond which binds together all the strange things of which I had
experience at the time and afterwards.
Mr.
19
Leopold stood with his back to an oak-tree, and I leant against
the fence beside him listening to him. He was a tall, dark man, with
a keen, thoughtful, and benevolent expression. He was quite strong
and healthy-looking, and there was a squareness about his features
that I think one does not often see in dark people. Mr. Furniss was of
lighter complexion and hardly as tall; there was quite as much
intelligence and benevolence in his face, but not so much of what I
have called thoughtfulness as distinguished from intelligence, and
there was a humorous glint in his eye which the other lacked. They
began to talk about the disease which had been so successfully dealt
with, and this was what they said:—
Leopold. The red sickness, of course. Can’t you see what I mean?
Furniss. No, I can’t. You’re too much of a mystic for me, Leopold;
but I’ll tell you what, England owes a debt to you and me, my boy,
for it was near enough to being a new edition of the black death or
the plague.
Leopold. Only the black death and the plague were imported, and
this
20
was indigenous. It sprung up under our noses in a healthy
place. It came from nowhere, and, thank God, it is gone nowhither.
Furniss. But surely the black death and the plague must have begun
somewhere, and they too seem to have gone nowhither.
Leopold. You’re right this far that they all must have had the same
sort of beginning. Only it is given to very few to see the beginning,
as you and I have seen it, or so near the beginning.
Furniss. Now, Leopold, I hardly see what you are driving at. I am not
much on religion, as they say in America, but I believe there is a
Power above all. Call that Power God, and let us say that God does
as He pleases, and on the whole that it is best that He should. I
don’t see that you can get much further than that.
Leopold. I don’t believe that God ever made the plague, or the black
death, or the red sickness.
Furniss. Oh, don’t you? Then you are, I suppose, what the
churchmen call a Manichee—you believe in the two powers of light
and darkness, good and evil. Well, it is not a bad solution of the
question as far as it goes, but I can hardly accept it.
Leopold. No, I don’t believe in any gods but the One. But let me
explain.
21
That is a nice dog of yours, Furniss. You told me one day
something about his breeding, and you promised to tell me more.
Furniss. Yes; but I have some distant cousins, and they have the
same breed and yet not the same, for they have cultivated it in quite
another direction.
Leopold. What are the differences?
Furniss. Our dogs are all more or less like Tommy here, gentle and
faithful, very intelligent, and by no means deficient in pluck. My
cousin’s dogs are fierce and quarrelsome, so much so that they have
not been suffered for generations to associate with children. And so
they have lost intelligence and are become ill-conditioned and low-
lived brutes.
Leopold. But I think I understood you to say that the change in the
breed did not come about in the ordinary course of nature.
Furniss. I believe not. I heard my grandfather say that his father had
told him that when he was a young man he had set about improving
22
the breed. He had marked out the most intelligent and best
tempered pups, and he had bred from them only and had given
away or destroyed the others.
Furniss. Just let me finish. It seems that while one brother began to
cultivate the breed upward, so to speak, another brother was living
in a part of the country where thieves were numerous and daring,
and there were smugglers and gipsies, and what not, about. And so
he began to improve the breed in quite another direction. He
selected the fierce and snappish pups and bred exclusively from
them.
Furniss. Just so, but I don’t quite see what you are driving at.
Leopold.
23
But one of them fulfils some obscure function in the
physique of the cow, some function certainly harmless and probably
beneficent, and the other is the malignant small-pox of the London
hospitals.
Furniss. So you mean to infer that in the latter case the germ has
been cultivated downwards by intelligent purpose.
Leopold. I don’t wish to use misleading words, but I will say that I
believe there are intelligences, not human, who have access to
realms of nature that we are but just beginning to explore; and I
believe that some of them are enemies to humanity, and that they
use their knowledge to breed such things as malignant small-pox or
the red sickness out of germs which were originally of a harmless or
even of a beneficent nature.
Furniss.
24
Just as my cousins have bred those wild beasts of theirs out
of such harmless creatures as poor Tommy’s ancestors.
Furniss. And you think that we can contend successfully against such
enemies.
Leopold. Why not? They can only have nature to work upon. And
very likely their only advantage over us is that they know more of
nature than we do. They cannot go beyond the limits of nature to do
less or more. As long as we sought after spells and enchantments
and that sort of nonsense we were very much at their mercy. But we
are now learning to fight them with their own weapons, which
consist of the knowledge of nature. Witness vaccination, and witness
also our little victory over the red sickness.
And so they got up and went back together to the dancers, nodding
to me as they went. I sat there for awhile, going over and over the
conversation in my mind and putting together my own thoughts and
Mr. Leopold’s.
Then I joined the company and was merry as the merriest for the
remainder
25
of the day. But that night I dreamt of strange-looking
clouds and of the shadows of invisible cars, and of demons riding in
the cars and sowing the seeds of pestilence on the earth and
catching away such evil specimens of humanity as James Redpath to
reinforce the ranks of their own malignant order.
26
CHAPTER III.
AT SEA.
I went in due course to Oxford, where I stayed the usual time. I did
not make any great failures there, nor did I gain much distinction. I
was a diligent reader, but much of my reading was outside the
regulation lines. The literature of my own country, the poetry of
mediæval Italy, and the philosophy of modern Germany, more than
divided my attention with classics and mathematics. Novels, mostly
of the sensational type, amused me in vacations and on holidays,
but very seldom found their way into my working days.