100% found this document useful (3 votes)
13 views

Fundamentals of Python: First Programs, 2nd Edition Kenneth A. Lambert - eBook PDFpdf download

The document provides information about the eBook 'Fundamentals of Python: First Programs, 2nd Edition' by Kenneth A. Lambert, including links for downloading and additional resources. It outlines the content structure, including chapters on algorithms, software development, loops, and data types, among others. The document also contains copyright information and notices regarding the use of the material.

Uploaded by

mreyemripza14
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
13 views

Fundamentals of Python: First Programs, 2nd Edition Kenneth A. Lambert - eBook PDFpdf download

The document provides information about the eBook 'Fundamentals of Python: First Programs, 2nd Edition' by Kenneth A. Lambert, including links for downloading and additional resources. It outlines the content structure, including chapters on algorithms, software development, loops, and data types, among others. The document also contains copyright information and notices regarding the use of the material.

Uploaded by

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

Fundamentals of Python: First Programs, 2nd

Edition Kenneth A. Lambert - eBook PDF download

https://ebookluna.com/download/fundamentals-of-python-first-
programs-2nd-edition-ebook-pdf/

Download more ebook from https://ebookluna.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookluna.com
to discover even more!

Fundamentals Of Python: Data Structures 2nd Edition Kenneth A. Lambert -


eBook PDF

https://ebookluna.com/download/fundamentals-of-python-data-structures-
ebook-pdf/

(eBook PDF) Fundamentals of Python: First Programs 2nd Edition

https://ebookluna.com/product/ebook-pdf-fundamentals-of-python-first-
programs-2nd-edition/

(eBook PDF) Building Python Programs 1st Edition

https://ebookluna.com/product/ebook-pdf-building-python-programs-1st-
edition/

(eBook PDF) Principles of Music 2nd Edition by Philip Lambert

https://ebookluna.com/product/ebook-pdf-principles-of-music-2nd-edition-by-
philip-lambert/
(eBook PDF) Evaluation of Health Promotion Programs 2nd Edition

https://ebookluna.com/product/ebook-pdf-evaluation-of-health-promotion-
programs-2nd-edition/

(eBook PDF) Fundamentals of Investing, First Canadian Edition

https://ebookluna.com/product/ebook-pdf-fundamentals-of-investing-first-
canadian-edition/

Fundamentals of Structural Analysis 5th Edition Kenneth M. Leet - eBook PDF

https://ebookluna.com/download/fundamentals-of-structural-analysis-ebook-
pdf/

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


PDF

https://ebookluna.com/download/essentials-of-anatomy-physiology-2nd-
edition-ebook-pdf/

(eBook PDF) Access Spanish: A First Language Course 2nd Edition

https://ebookluna.com/product/ebook-pdf-access-spanish-a-first-language-
course-2nd-edition/
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.
Discovering Diverse Content Through
Random Scribd Documents
to make something out of your life—like Ted Mackay. There was no
more time to be wasted.
"Promise me you'll go," begged Ralph, leaning over eagerly and
putting his hand on her arm.
Instinctively she drew it away, but before she could answer, Louise
and Maurice appeared from a cross-path that was hidden by tall
bushes.
"Why, there's my little Lindy!" cried Maurice, though Linda was
several inches taller than he was. "Grieving for papa?"
"Shedding tears," laughed Linda. But the words made her think of
her own father, and she grew sober. Suppose he were home now—
waiting for her! He never stayed more than a day; how she would
hate to miss him!
"Has anybody found the treasure yet?" she inquired.
"I've found two treasures," replied Maurice complacently, looking
first at Louise and then at Linda.
"Forget it!" commanded Louise, tersely, lifting her head. She, like
Linda, was tall, but in that the resemblance ended. Her dark, sleek
hair was short and almost straight, and she wore earrings—even in
swimming. She said she felt undressed without them—"practically
immodest," were her exact words.
"No, but really—?" persisted Linda.
A wild shout from Dot Crowley, followed by a chorus of "Whoopee!"
from half a dozen others, answered Linda's question immediately.
Dot always was lucky. The others ran to the spot where the crowd
was gathered, and Dot, a tiny, vivacious blonde, who could take
child's parts in the amateur plays, was holding two boxes of golf
balls triumphantly up to view.
"Do I have to give one box to that lazy kid?" she demanded, pointing
scornfully at her long-legged partner, Jim Valier, who had been
languidly following her around. At the time when she had discovered
the prize, he was lolling under a tree, resting his "weary bones," as
he said, smoking a cigarette.
"Sure you do!" he drawled. "Didn't I supply the brains to our
combine?"
"Brains!" repeated Dot. "Where did you get 'em? I'll have to have
you arrested for stealing 'em, if that's the case! But here—take your
box!"
"Couldn't possibly," he said, waving them aside with his cigarette
holder. "Besides, I hardly ever play golf. Too fatiguing."
"How about your school-girl figure?" asked Maurice. "Aren't you
afraid if you don't exercise, you'll lose it?"
Everybody, even Linda, laughed, for Jim Valier was about the world's
thinnest youth.
"He's really afraid somebody will mistake him for a golf-stick, and
bang a ball with him," remarked Ralph.
In groups, and some in pairs, the whole crowd went back to the
lake. After all that exercise and excitement, everybody wanted
another dip to cool off. It was six o'clock by the time they all piled
into their cars, and half-past when Linda reached home.
Hoping to find her father, as she had been hoping every day that
week, she dashed up the steps quickly, merely waving good-by to
her companions as the sports car shot from the driveway. And then,
miraculously, she saw his beloved face at the door!
"Daddy!" she cried rapturously, rushing breathlessly into his arms.
He was taller than Linda, with a straight, lithe figure like that of a
much younger man. His hair was dark, with just a little gray at the
temples, and his skin deeply tanned from his out-door life. A sort of
habitual smile played about his lips, as if he had made up his mind
to find life pleasant, no matter what came.
"My dear little girl!" he said, quietly, patting her hair. "Will you
forgive me for coming a day too late? Your Aunt Emily tells me that
both Commencement and class-day are over—and you are an old
Grad now!"
"Yes, but I don't mind, Daddy, so long as you came today!" she
replied, squeezing his hand. "Maybe it's better this way, because I've
been so rushed lately that I wouldn't have had much time to see
you."
"You must tell me all about everything," he said, drawing her arm
through his, and leading her down the steps of the porch. Of course
he thought he meant what he said, but Linda knew from experience
that if she did tell him, he wouldn't be listening. A dreamy
expression so often came into his eyes when she chattered, and she
would wonder what he was thinking of. Strange lands—or his ranch
out west—or perhaps her mother?
"Where are we going?" she asked. "I really ought to dress for dinner,
Daddy. You know what picnics are."
"Yes, To be sure. But I want to show you your graduation present."
"My present?" There was excitement in her tone; it was sure to be
something wonderful—and unusual. All the girls were wild with envy
when Kitty Clavering received a real pearl necklace from her father.
All—except Linda. She had no desire for pearls, or for any jewelry,
for that matter. She had known that her father's present would be
much more thrilling. At least—if he didn't forget!
"You didn't think your old Dad would forget you, did you, Honey?"
he asked.
"No—no—of course not.... But, Daddy, where is it? Why are we
going out back of the house?"
"We have to walk over to our big field across the creek," he
explained, mysteriously.
"The big field? Why?... That's a hot walk, Daddy. No shade at all! If
you want a nice walk, we ought to go in the other direction, down
towards the orchard, where there are some trees."
"Trees are the one thing we don't want," he replied, solemnly.
"You're going to hate trees, after you get my present, daughter."
"Hate—trees?" Linda's eyes were traveling all over the landscape,
scanning it in vain for a clew. And then, as they mounted a slight
incline, the thing came into sight. The marvelous, wonderful present!
Too good to be true! Her heart stopped beating, her legs shook. She
clutched at her father for support.
A beautiful, shining airplane! A superb Arrow Sport! The very kind
she had been reading about, had been longing some day to possess!
And even a hangar, to keep it in safety!
"Daddy!" she gasped, hoarsely.
He was watching her face, rapturously.
"You like it?"
"Oh!" she cried, wrapping her arms around his neck, and suddenly
bursting into tears. "How could you know that I wanted it so much?"
He patted her hair, a little embarrassed by her emotion.
"I just tried to imagine what I would want most if I were your age....
You know, dear, you're your father's own girl! You look like your
mother, but you're much more like me.... A strange mixture...." He
was talking more to himself now, for Linda was almost running,
pulling him along excitedly. "Feminine beauty—with masculine
ambition...."
But Linda was not listening. She had reached the plane now, and
was walking around it, enthralled. Touching its smooth surface, to
make sure that it was not only a dream. Dashing back to hug her
father, and then climbing into the cockpit, to examine the controls,
the instruments, the upholstery. If she lived to be a hundred years
old, no other moment could hold greater happiness than this!
Her father smiled softly in satisfaction. He wanted her to have all the
happiness that he had somehow missed. Money couldn't buy it for
him; but money spent for his daughter could bring it to him in the
only possible way now.
"You're not a bit afraid?" he asked, though he knew from her shining
eyes that his question was unnecessary.
"Dad!"
"And now the question is, who can teach you to fly? Unfortunately,
the man who brought it here for me couldn't stay, even to explain
things to you—although of course there is a booklet. But I
understand there's an air school here at Spring City...."
"Yes! Yes!" she interrupted. "I've been there—been up with one of
the instructors. Can we drive over for him tonight?"
"My dear, you can't take a lesson at night," he reminded her. "You
know that."
"Oh, of course not!" she agreed, laughing at her own folly. "But
tomorrow?"
"Yes, certainly. At least we can see about it. You have to pass a
physical examination first, I understand."
"And I want to take the regular commercial pilot's course, Daddy! I
want to go to the bottom, and learn all about planes, and flying. May
I?"
"I don't see why not.... You needn't stop for the expense."
Linda blushed; she hadn't been thinking of the expense—she never
did. But perhaps she ought to now, for the plane must have cost a
lot of money. At the present, however, something else was worrying
her.
"It was the time I was thinking of," she admitted. "Aunt Emily wants
to go away in a week or so. And oh, Dad, I just couldn't bear to
leave this!" There were actually tears in her eyes.
"Of course not, dear. Well, we'll see if we can't compromise with
your aunt. Stay at home the rest of June and July, be content with a
private pilot's license for the present, and then go away in your
plane in August. Wouldn't that suit you?"
"To the ground—I mean to the skies!" corrected the happy girl.
"And now we must get back to dinner," he reminded her. "Aunt
Emily's waiting."
Solemnly, tenderly, as a mother might kiss her baby, Linda leaned
over and kissed the beautiful plane. Then giving her hand to her
father, she walked back to the house with him in silence, knowing
that now her greatest dream was fulfilled.
Chapter IV
Summer Plans

The news of Linda's magnificent present spread like wildfire. She


never knew how it got about, for she didn't call anybody. In fact, she
would have preferred to keep it a secret for that evening at least,
and just spend her time over the booklet, talking things over with
her father.
But of course the rest of the crowd couldn't understand that. These
young people, who saw their parents every day of their lives, just
couldn't believe that a normal fun-loving girl like Linda would prefer
a father's society to theirs. They didn't know that Linda had always
longed to know him better, to understand him, to talk over with him
her greatest dreams and ambitions. Because there had been nobody
to talk to in that intimate fashion. Aunt Emily never had understood
her, and never would. The kind-hearted woman saw, of course, that
her niece was pleased with her graduation present, but she could
not realize the girl's overwhelming joy in the possession of a plane.
To her, even a string of imitation pearls would have been more
desirable.
They talked their plans over at dinner, Linda's father taking her side
in urging that the vacation be postponed until August.
"You don't mind, do you, Emily?" he asked his sister.
"Well, I can't say I don't mind," she replied, a little sharply. "But of
course I wouldn't spoil Linda's fun. But I am wondering whether you
have been wise, Tom. Linda is tired out; instead of going to school
and learning some more, she ought to be resting.... But your
presents have never shown a great deal of wisdom, I fear."
Her brother laughed.
"Sometimes it's better to be foolish," he remarked.
"Not if Linda breaks her neck!"
"Which she isn't going to do!" contradicted Mr. Carlton, confidently.
"Linda's careful—and she's thorough. I know that, from the way she
drives her car—and takes care of it."
"Cars and airplanes are different matters!"
"Not so different as you might think. In some ways, cars are more
dangerous, because you have to consider traffic—what the other
fellow is going to do. And there's so much room in the skies!"
"But if something goes wrong—there's nobody there to help her,"
objected Miss Carlton.
"Well, Emily, you'd be amazed at the perfection of the airplanes they
are putting out now-a-days. They're as different from the old-
fashioned ones of the World War, as the first two-cylinder
automobiles from the sixes and eights of today."
"But there still are a lot of crashes—and deaths," insisted his sister.
"That doesn't say Linda will crash! Linda is going to be a good pilot—
learn it all thoroughly!... Why, Emily, you don't think I'd be willing to
take any chances with my only child, do you—if I didn't consider it
safe?"
He smiled fondly at Linda, but his sister drew down the corners of
her mouth a trifle scornfully. As if his affection could compare with
hers, though Linda wasn't her own child! He saw the girl two or
three times a year at the most, while Aunt Emily was with her every
day of her life!
"Well," she added, "I'm afraid you'll feel out of the crowd by the time
August comes and they have been together all that time at Green
Falls!"
"Do you mind missing it, my dear?" her father asked, gently.
"Not a bit!" replied Linda immediately, her eyes shining at the
thought of what she was gaining.
Miss Carlton abruptly changed the subject.
"Do you remember a man named Clavering, Tom?" she asked.
"I remember the name. Connected with oil, wasn't he? Very
wealthy?"
"A millionaire, I think," replied Miss Carlton, as if the news were the
most important thing in the world. "Well, he has bought an estate
just outside of Spring City, and his daughter has just graduated in
Linda's class."
"Yes?" remarked her brother, wondering what possible difference
that could make to him.
"Well, the Claverings are planning to spend the summer at Green
Falls, on Lake Michigan—the resort that Mrs. Haydock and I have
selected.... And there is a son in Harvard, who is going to be there."
"Yes?" It still didn't dawn on the man what his sister meant. Perhaps
that was because he was not worldly, and money and position didn't
mean much to him. Or perhaps it was because it had never occurred
to him that his little Linda was old enough to be thinking about
getting married.
"You certainly are slow at comprehension at times, Tom," she said,
"for a smart man. Do I have to tell you in so many words that young
Ralph Clavering is interested in Linda?"
Linda blushed, and Mr. Carlton opened his eyes wide in amazement.
"Well! Well! Well!" he exclaimed.
"Dad!" protested Linda, nervously. "Don't be so serious! Aunt Emily
thinks that because she loves me, everybody thinks I'm grand. But
as a matter of fact, Ralph Clavering doesn't like me any better than
half a dozen other girls. And I don't believe he likes me nearly so
well as Louise—though I haven't given the matter any thought."
"How any boy could fall for Louise Haydock is more than I can see!"
put in Miss Carlton. "She is a nice girl, but she has ruined what looks
she had by cutting her hair off so short, and wearing those dreadful
earrings all the time——"
"Aunt Emily!" interrupted Linda. "Please don't forget that Louise is
my best friend!"
"Even so, I don't have to admire her appearance, do I?"
In a man's fashion, Mr. Carlton was getting very tired of this small
talk. He stirred restlessly.
"Well, it's settled then, about the summer, isn't it?" he asked. "I'd
like to drive over early tomorrow morning to this Flying School, and
make the arrangements about your course. Because tomorrow night
I'm taking the sleeper back to the ranch."
"Dad!" cried Linda, in disappointment. "You don't have to go that
soon, do you? Oh, I wanted you to see me fly!"
"I'll be back again, as soon as I can. But just now I'm having trouble
with some Mexicans who came over the border and have been
threatening us. I've got to be on the job. My help aren't any too
reliable."
"You won't be in any danger will you, Daddy?"
He shrugged his shoulders indifferently.
"Guess not," he replied.
At the conclusion of the meal, Miss Carlton, who always liked to have
Linda's young friends about, suggested that she call some of them
on the telephone and give them her news, inviting them over to
celebrate with her. But Linda shook her head.
"There's only one person I'd like to tell about it," she said, "and I'm
afraid I couldn't reach him by phone, for I don't know where he
lives. That's a boy over at the school, who has taken me up a couple
of times."
But, as friends like this did not interest her, Miss Carlton dismissed
the subject and went out to consult her cook. Linda's father,
however, felt differently.
"What's his name?" he asked, indulgently. "Maybe we could locate
him, if we put in a call at the school. There would probably be
somebody about who would know his address."
"Ted Mackay," answered Linda.
Mr. Carlton's eyes narrowed suspiciously, and the smile died from his
lips. His daughter trembled. What could he possibly have against
Ted?
"What's the fellow look like?"
"He's big—with red hair, and blue eyes, Why? Do you know him,
Daddy?"
"Think I know his father—to my sorrow. Same name—description
fits, too. Likable chap, when you first meet him, isn't he? Looks
honest and kind, and all that?"
"Oh yes, Daddy! And he is so nice, too. And so clever!"
"I don't doubt it. So is his father—in his own way. Well, if he's the
son of the man I know, you're to keep away from him. Do you
understand, daughter?"
"Yes, but Daddy, don't you think it's only fair to give me a reason?"
she pleaded.
"I'd rather not. Can't you take my judgment as worth something,
Linda?" He spoke sternly.
The tears came to Linda's eyes, and she looked away.
"Mayn't I even speak to him?" she asked, finally.
"Oh, certainly. Never cut anybody—it's a sign of a little mind to stoop
to such childishness. But don't be friendly with him. I dare say there
are other instructors at the field, and I'll arrange for someone else to
teach you."
The door-bell rang three times, but before the maid could answer it,
Louise Haydock dashed into the house, followed by Kitty and Ralph
Clavering, and finally, Maurice Stetson.
"Whoopee!" cried Ralph, almost running into Linda's father, who was
standing in the dining-room doorway.
"Darling!" exclaimed Louise, embracing her chum excitedly. "We
heard the news! Congratulations!"
"And naturally we couldn't wait to see your plane," added Kitty. "But
are you sure you've finished dinner?"
"Yes, indeed," replied Linda, introducing her father to everybody
except Louise, who of course knew him.
"If it only isn't too dark to see it!" exclaimed Louise. "We've all
brought flashlights."
"Then we better trail out immediately," laughed Linda. "And I'll get
Aunt Emily. She has only seen it from a distance."
"Better wait for the rest of the crowd," suggested Ralph. "I saw Dot
trying to round up some more. They ought to be here any minute."
"Then we might as well wait. Aunt Emily'll be here in a minute."
"What kind of plane is it, Linda?" inquired Maurice. "You're 'Lindy'
Junior now aren't you—just as I predicted," he added.
"It's a 'Pursuit,'" answered Linda, ignoring his second remark. "An
Arrow Sport."
"Open cockpit?" asked Ralph.
"Yes. See—here's its picture." She waved the folder towards the
boys. "It's supposed to be a wonderful little plane for a beginner!"
"From now on, Linda'll talk of nothing but joysticks and ailerons and
—" began Maurice, but he was interrupted by the arrival of Dot
Crowley and six other young people, all of whom had been packed in
her small car.
It was just as she liked it to be, Aunt Emily thought, as she joined
the merry, singing group, and started out with them towards the
field beyond the house. Mr. Carlton did not go with them this time,
and later on, Linda had reason to be thankful for his absence.
It was quite dark now, but both the moon and the stars shone
brightly, and the plane was clearly visible. The exclamations of
delight and praise from her guests were enthusiastic enough to
satisfy any proud owner of such a glorious prize. Linda was happier
than ever.
The boys were naturally interested in the mechanics of the plane,
the girls in the upholstery of the seats, the charming, deep cushions,
which could be removed if it were necessary to use a parachute.
They turned on their flashlights, and walked about the biplane, not a
little in awe at the idea of Linda's piloting it through the skies.
"It only holds two people," remarked Dot, regretfully. "I wonder if
we could pile in extras, like I do with my car."
"I'm afraid not," replied Linda. "But I can take everybody up in turn
—after I get my license. I am hoping to bring it to Green Falls in
August."
Satisfied at last that they had seen as much as possible for the
present, they started to turn back, when Maurice suddenly spied a
lonely figure at the top of the incline, some fifty yards away.
"What ho!" he exclaimed. "Who can that be? Yo-ho-ho!" he cried,
making a funnel with his hands.
"Not anybody in our crowd," replied Jim Valier, "or he would answer.
Hope it isn't a thief—with designs on your new plane."
"We better chase him!" said Jackson Stiles, who was always ready
for adventure, "Come on, fellows, let's rush him!"
The boys darted off, all except Jim Valier, who said gallantly that he
had better stay as protection for the ladies, though of course
everybody knew it was only because he was too lazy to run. The
girls laughed and chattered while they were gone—all except Linda,
who waited nervously to find out what success they had had.
In less than three minutes, however, they had returned,
shamefacedly admitting defeat.
"Maybe the fellow couldn't sprint!" announced Ralph. "I'll bet he's a
track-runner——"
"Or a chicken thief!" suggested Maurice.
"Do you think he is a tramp?" inquired Miss Carlton, relieved that the
man had disappeared. Tramps were so dirty, so unpleasant!
"Don't think so. Big fellow—not badly dressed, as far as we could
see. Had red hair."
"Too bad we couldn't catch him," remarked Maurice, always ready
with his jokes, "for his hair was bright enough to light up the plane.
We wouldn't have needed our flashes."
"Might have set the 'Pursuit' on fire!" suggested Jim.
Linda frowned uneasily. The description sounded like Ted Mackay.
But how did he know that she had a plane, and if he had happened
to see it, why didn't he come to the house, and ask her permission
to examine it? After all, it was on their own property—nobody had
any right to intrude. She thought darkly of what her father had said,
and hoped that there wasn't anything crooked about Ted. Why, he
seemed more of a friend to her than any of these people—except of
course her Aunt Emily, and Louise!
By the time they had reached the house, everybody had forgotten
the incident, for Louise turned on the radio, and without consulting
Linda, they all decided to dance. Ralph claimed the latter for the first
waltz.
"So this will make a change in your summer plans," he said, as if the
idea were not wholly to his liking.
"Yes. We're not going to Green Falls till August—maybe not then, if I
don't succeed in getting a private pilot's license before that."
"But what about me?" he inquired, and the admiring look he gave
her would have pleased Miss Carlton, had she noticed it.
Linda looked puzzled.
"You? Why—you'll never miss me! With all your girl friends!"
"No; I've decided I'm not going to miss you," he said, quietly.
"Because I'm going to stay right here in Spring City, and learn to fly
along with you!"
"What?"
"Yes. The thing fascinates me. I want a plane, too! I'm going to
touch my Dad for one when I get home tonight!"
"But you've promised everybody you'll go to Green Falls!"
"So I will—August first!"
And so, much to Miss Carlton's delight, when the rest of the crowd
left Spring City the following week, Ralph Clavering stayed at home
with a couple of the servants, and enrolled at the same time as
Linda, at the Spring City Flying School.
Chapter V
The First Lesson in Flying

Early the next morning, Linda wakened her father and hurried him
through his breakfast. There wasn't a moment to be lost, she told
him excitedly, like a child waiting to open her Christmas stocking.
She had her car under the portico before he had finished his second
cup of coffee.
"Don't drive so fast that you are killed on the way," cautioned her
aunt. "Remember, dear, you have the rest of your life to fly that
plane!"
But the present moment is the only time of importance to young
people, and Linda scarcely took in what she was saying. Besides, the
caution was unnecessary; unlike Dot Crowley and Maurice Stetson,
she had too much respect for her car to mistreat it by careless
driving. Linda loved her roadster as a cavalry general loves his horse.
"You want to do most of your learning on your own plane, don't you,
daughter?" asked her father, as he sat down beside her. "I mean—
you'd rather bring your instructor back with us, and fly it, wouldn't
you?"
"Of course, if that is possible. But don't you suppose I have to go in
a class with others, Daddy?"
"Probably not—for it is a small school. Besides, I can arrange for you
to have private lessons. It will hurry things up for you."
"Oh, thank you, Daddy!... But later, I want to go to a regular ground
school, if you will let me." Her tone was as eager as any boy's,
starting out on his life work. "And study airplane construction, and
wireless—and—and——"
He smiled at her approvingly. What a girl!
"You are ambitious, my dear," he said, but there was pride in his
words. "I don't see why not, though.... Only, not all at once. As your
Aunt Emily reminded you, you have the rest of your life."
"I can't bear to fool!" she exclaimed, impatiently. "Now that I have
graduated, I want to get somewhere."
"You're bound to—unless you fly in circles," he remarked, lightly.
"I mean—oh, you know what I mean, Daddy! And you do
understand, don't you?"
"Well, not exactly. You don't expect to be one of those independent
girls who insist upon earning their own living, do you, dear?"
"I don't know...." Somehow, she couldn't explain. Nobody
understood just what she wanted except Ted Mackay, and that was
because he had the same sort of goal himself. Ted Mackay! The
memory of her father's command hurt her. Must she really give up
his friendship? But why? She wanted to ask her father, but he was
looking off in the distance, apparently lost in his own thoughts.
So she drove the remainder of the way in silence, absorbed by her
own dreams.
The field was outside of Spring City, covering an area of thirty acres,
and surrounded by the white fence that was now being used so
much by airports. Three large hangars, containing probably half a
dozen planes, occupied one side of the field, and, near the entrance
was a large building, evidently used as an office and school for the
theoretical part of the courses.
"You have been here before, Linda?" asked her father, as the girl
locked her car.
"Yes—a couple of times. I feel almost at home."
Scarcely were they inside the grounds, when Ted Mackay, looking
huge and handsome in his flyer's suit, came out of the office
building. He recognized Linda at once, and his blue eyes lighted up
in a smile of welcome. Since he wore his helmet, his red hair was
not visible, and Linda, glancing apprehensively at her father, knew
that the latter had no idea who Ted was. But, nervous as she was
over the meeting that was about to take place, she could not help
feeling proud of Ted, and warmed by the frankness of his happy
smile.
"Linda!" he cried. (She had called him Ted the second time she met
him, so he reciprocated.) "I owe you an apology—and a confession!"
"Yes?" replied Linda, glancing fearfully at her father, though she
knew that he had not yet realized who the young man was, or his
expression would not have been so beneficent. "But first I want you
to meet my father," she said. "Dad—this is Ted Mackay."
She was vexed at herself that she was actually stammering. Acting
just like a child! Yet she couldn't forget how stern her father could
be. She recalled the day that, as a child, she had sneaked off and
played with Louise when her chum had whooping cough. Her father
happened to come home—and announced that he would take care
of her punishment. And what a punishment! For three whole weeks
he made her stay in the house, without a single companion except
her Aunt Emily! He said he'd teach her to obey.
But he wasn't storming, or even frowning now. Merely looking
politely indifferent, perhaps a trifle superior. He made no motion to
shake hands with Ted.
"How do you do?" he said. "Would you be kind enough to take us to
the man in charge of this field?"
"Certainly, sir," replied Ted.
Immediately, as if he intended to give the young people no chance
for personal conversation, Mr. Carlton began to ask about the
courses that were offered.
Ted answered his questions, explaining that Miss Carlton would
probably want to become a private pilot at first.
"You have to pass a physical examination," he said, "and get a
permit from the Government. Then you must have at least eighteen
hours of flying experience—ten with someone else with you, eight of
solo flying. There is a written examination, too—all about the rules
and regulations that make up the laws of the air. Of course there
isn't a lot of traffic, like with the driving of cars," he explained,
smilingly, "but you'd be surprised at how many rules there are!"
They had been crossing the field while he talked, and they stopped
now at the main building. With a nod of dismissal that was curt, and
yet not quite rude, for a muttered, "Thank you," accompanied it, Mr.
Carlton left Ted, and took his daughter inside.
A middle-aged man, dressed in a khaki shirt and breeches, was
seated at a desk. He looked up as they entered.
"My name is Carlton," began Linda's father, "and this is my daughter.
I have bought her a plane, and I have come over to arrange about
some lessons in flying."
Lieutenant Kingsberry, a former Army officer, asked them to be
seated, and went over about the same explanation that Ted had
given, saying that he would be delighted to register Linda, provided
that she passed the physical examination.
"I suppose it is not so unusual now to have girls as students?"
inquired Mr. Carlton.
"Not for many of the schools," replied the lieutenant. "But it just
happens that we so far have not enrolled any of the fair sex. Your
daughter will be the first. When does she wish to start?"
"As soon as possible," replied Mr. Carlton.
"Now!" Linda could not help adding.
"Well, I don't see why not," agreed the lieutenant, leniently. "At least
Miss Carlton could take the physical examination, because one of our
doctors is here now. And if she passes that, Mackay can give her the
first lesson."
Linda's expression of delight suddenly died on her lips. For she
glanced at her father, and saw the queer, drawn look about his
mouth at the mention of Ted's name.
"This—Mackay—" he said slowly, "he isn't your only instructor?"
"He is our best."
"I prefer someone else. Can you arrange it?"
"Why—I suppose so. But if it is only personal reasons, I think you
are making a mistake, Mr. Carlton. Mackay is our most reliable flyer
—by far our best instructor. We don't expect to have him here more
than a month or so. He's had a good offer from a big company."
Linda was glancing shyly, pleadingly, at her father, but he did not
even see her.
"Unfortunately I found this young man's father to be most unreliable
—untrustworthy—during the period that I employed him on my
ranch. The fact is, we are not yet through with the trouble that he
started. So you can understand why I should refuse to trust my
daughter to his son. It is an unpleasant but true fact that children
inherit their father's weaknesses. I should not have a comfortable
minute, being miles away, and knowing that she was in his hands."
"Of coarse I will accept your decision, Mr. Carlton," replied
Lieutenant Kingsberry, "and see that your wishes are carried out. I
will summon the second ranking instructor—H. B. Taylor."
He called his office boy, a young man learning to fly, and working his
way at the same time, and gave the necessary message. A couple of
minutes later the man came in, dressed like Ted, but somehow he
seemed insignificant to Linda—as if he were the one who was not
reliable. She sighed.
Her father remained with the lieutenant and the instructor while she
went into the doctor's office for her physical examination. She knew
that her eyesight was good, but she felt a little nervous when the
doctor examined her heart. It was fluttering so! Suppose all the
excitement had been too much for her—and she did not pass! What
good would her lovely plane be to her, if she were never allowed to
pilot it herself?
But she need not have been alarmed, for she came through with
flying colors. Then young Taylor took her over to one of the planes,
and began to explain about the joystick, the rudder, the ailerons,
and everything else he could think of, in words of one syllable.
Linda glanced at him, frowning. Did he think she was a baby. Or was
it because she was a girl that his manner seemed so superior, so
condescending? Why, he was wasting a lot of time! Ted would have
had her up in the air by this time, perhaps letting her guide the
plane herself.
"I am familiar with all these terms, Mr. Taylor," she interrupted. "You
see I have been up twice—with Mr. Mackay. And I've read a couple
of books."
The young man regarded her haughtily.
"It is necessary, Miss Carlton, that you go through the regular
lessons, regardless of what you knew beforehand," he answered
coldly. "And whatever Mr. Mackay may have shown you—as a friend
—has nothing to do with these lessons, so long as I, not he, am your
instructor."
"But I want to go up today!" she protested, eagerly.
"It is not our custom to take students up on the first day, Miss
Carlton.... Now, have you a notebook and pencil?"
"In my car." She tried to answer naturally, but she was keenly
disappointed.
"Then will you please go and get them," he said, seating himself in
the cockpit of the plane which he had been using to illustrate his
statements.
Obediently, but half-heartedly, Linda started back for the road where
her car was parked. She had gone about half-way when she came
upon her father, accompanied by Ralph Clavering, dressed like
herself, in his riding outfit.
"Hello, Linda!" he cried. "Passed your physical exam, didn't you?"
"Oh, yes," she answered. "So you're really going to learn, too?"
"I most certainly am. And your father has consented to let us take
our lessons together. Won't that be fun?"
"Linda," interrupted her father, as he saw her start away, "where are
you going? I want to tell you something."
"Yes, Daddy?" A wild hope surged in her heart that perhaps he had
changed his mind about Ted. It wasn't only that she had taken a
dislike to H. B. Taylor—it was rather that she had not confidence in
him as a teacher. He might be all right as a pilot, but instructing
others was a different matter. And he would never really feel any
personal interest in her progress, or understand her, like Ted. His
attitude almost said that he thought it was silly of girls to want to
fly!
But she ought to have known her father better than to think he
would change his mind.
"I should like to take your car and go home now, if you don't mind,"
he said, "because I have some work to do today that is urgent—
some people to see about business. And Mr. Clavering has very
kindly offered to drive you home. Is that all right? I know you don't
like other people to run your car——"
"Oh, Daddy, you're different," she said, forcing a smile. "Of course I
don't mind your driving it.... But I'm sorry you can't wait for us."
Promising to meet Ralph in a couple of minutes, she walked out to
the entrance of the field with her father.
"I need not tell you, dear," he said, "that my decision about Mackay
is final. And I want you to have as little to do with him as possible,
while you are here. It's for your own good, daughter. I can see that
girls might find the young man attractive. But it is well to steer clear
of such people. Have all the fun you like with your own friends."
"Yes, Daddy," she managed to reply.
"I guess young Clavering will see to it that your time at home, after
most of the others go away for the summer, is not dull. And if you
pass your course and get your license, you can fly your plane to
Green Falls. I will make arrangements about a place to keep it. I
dare say they have maps at the school."
"Yes—and thank you so much—for everything, Daddy," she said. She
mustn't let him see that she was disappointed, after all he had done
for her! He might be right about Ted—but she didn't think so.
Whatever Ted's father might be, she felt sure that Ted was one of
the finest young Americans that she had ever known.
Securing her notebook, and handing over her keys to her father, she
hurried back to the field, and finished her lesson with Ralph at her
side. As they walked out together, she looked about shyly for Ted. It
wouldn't do any harm for her just to speak to him; after all he did
want to tell her something. At last she spotted him, across the field
beside one of the planes—in overalls and jumper now, his red hair
brilliant in the sunlight.
"Do you know I believe that's the fellow we chased last night!"
exclaimed Ralph. "Do you know him?"
"Yes, I've met him. He took me up a couple of times."
"You know him? Then why was he sneaking around so funny last
night? Why didn't he come over and speak to you?"
"He's shy," replied Linda, jumping to the only conclusion that
seemed feasible, and her explanation must have been correct, for
Ted never looked up from his work as the young couple passed.
Chapter VI
Winning Her License

The next few weeks were the most interesting, the most exciting, of
Linda's whole life. Every day she drove over to the Flying School with
Ralph, and gained first her theoretical, and then her practical
knowledge.
Both she and Ralph were surprised to find that it was so simple a
matter to handle a plane. By the middle of July they were
accustomed to stepping into the cockpits by themselves, nosing their
planes into the wind, and rising to a height of fifteen hundred feet,
without even a tremor. Anxiously they counted their hours of solo
flying, not only that their licenses would be approved, but because
they both wanted to try some stunts. They had studied the
principles of loops, Immelman turns, barrel rolls, and falling leaves,
and they were wild to try them out for themselves.
Finally, after they had both passed their written examinations, and
were only waiting for their licenses to come through, Mr. Taylor
allowed them both to try an inside loop and an Immelman turn.
Linda's happiness was so great that she felt she just had to tell
somebody, so she went home and wrote to her father. Unfortunately,
she thought it wiser to say nothing about stunts to her aunt.
Miss Carlton still insisted that she would never get into a plane, not
even Linda's. "It's too dangerous," she objected, when her niece was
begging her to go for a ride. "I might be killed—and then who would
take care of you? And besides, I don't see how anybody could learn
to fly in the short time you've been at it."
"But Aunt Emily," explained Linda patiently, "it really is easier than
driving a car. Once you are off the ground, the plane practically flies
itself. And the higher you are, the safer."
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!

ebookluna.com

You might also like