100% found this document useful (4 votes)
100 views55 pages

Complete Invent Your Own Computer Games With Python 3rd Edition Al Sweigart PDF For All Chapters

Computer

Uploaded by

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

Complete Invent Your Own Computer Games With Python 3rd Edition Al Sweigart PDF For All Chapters

Computer

Uploaded by

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

Download the full version of the ebook at

https://ebookgate.com

Invent Your Own Computer Games with Python


3rd Edition Al Sweigart

https://ebookgate.com/product/invent-your-own-
computer-games-with-python-3rd-edition-al-
sweigart/

Explore and download more ebook at https://ebookgate.com


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

Invent Your Own Computer Games with Python 4th Edition Al


Sweigart

https://ebookgate.com/product/invent-your-own-computer-games-with-
python-4th-edition-al-sweigart/

ebookgate.com

OpenCV Computer Vision with Python 1st Edition Howse

https://ebookgate.com/product/opencv-computer-vision-with-python-1st-
edition-howse/

ebookgate.com

Make Games with Python 1st edition Edition Sean M. Tracey

https://ebookgate.com/product/make-games-with-python-1st-edition-
edition-sean-m-tracey/

ebookgate.com

Make Fun Create Your Own Toys Games and Amusements First
Edition Bob Knetzger

https://ebookgate.com/product/make-fun-create-your-own-toys-games-and-
amusements-first-edition-bob-knetzger/

ebookgate.com
OpenCV with Python blueprints design and develop advanced
computer vision projects using OpenCV with Python 1st
Edition Michael Beyeler
https://ebookgate.com/product/opencv-with-python-blueprints-design-
and-develop-advanced-computer-vision-projects-using-opencv-with-
python-1st-edition-michael-beyeler/
ebookgate.com

Learning Opencv 3 Computer Vision with Python 2nd Edition


Joe Minichino

https://ebookgate.com/product/learning-opencv-3-computer-vision-with-
python-2nd-edition-joe-minichino/

ebookgate.com

On your own how to start your own CPA firm Second Edition
Poe

https://ebookgate.com/product/on-your-own-how-to-start-your-own-cpa-
firm-second-edition-poe/

ebookgate.com

Computational Physics Problem Solving with Python 3rd


Edition Páez

https://ebookgate.com/product/computational-physics-problem-solving-
with-python-3rd-edition-paez/

ebookgate.com

Tiny Python Projects Learn coding and testing with puzzles


and games 1st Edition Ken Youens-Clark

https://ebookgate.com/product/tiny-python-projects-learn-coding-and-
testing-with-puzzles-and-games-1st-edition-ken-youens-clark/

ebookgate.com
Invent Your Own
Computer Games
with Python
3rd Edition

By Al Sweigart
ii http://inventwithpython.com

Copyright © 2008-2015 by Albert Sweigart

Some Rights Reserved. "Invent Your Own Computer Games with Python" ("Invent with Python")
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States
License.

You are free:

To Share — to copy, distribute, display, and perform the work

To Remix — to make derivative works

Under the following conditions:

Attribution — You must attribute the work in the manner specified by the author or
licensor (but not in any way that suggests that they endorse you or your use of the work).
(Visibly include the title and author’s name in any excerpts of this work.)

Noncommercial — You may not use this work for commercial purposes.

Share Alike — If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same or similar license to this one.

Your fair use and other rights are in no way affected by the above. There is a human-readable
summary of the Legal Code (the full license), located here:
http://creativecommons.org/licenses/by-nc-sa/3.0/us/legalcode

The source code in this book is released under a BSD 2-Clause license, located here:
http://opensource.org/licenses/BSD-2-Clause

Book Version 3.0.1, ISBN 978-1503212305

Attribution: Treasure chest icon by Victor Escorsin, Sonar icon by Pantelis Gkavos

If you’ve downloaded this book from a torrent, it’s probably out of date. Go
to http://inventwithpython.com to download the latest version instead.

Post questions to http://invpy.com/forum


For Caro, with more love

than I ever knew I had.


iv http://inventwithpython.com

A Note to Parents and Fellow Programmers


Thank you for reading this book. My motivation for writing it came from a gap I saw in today’s
literature for kids interested in learning to program. I started programming in the BASIC
programming language with a book similar to this one.

During the course of writing this, I've realized how a modern language like Python has made
programming far easier and versatile for a new generation of programmers. Python has a gentle
learning curve while still being a serious language used by programmers professionally.

The current crop of programming books fall into two categories. First, books that didn’t teach
programming so much as “game creation software” or a dumbed-down languages to make
programming “easy” to the point that it is no longer programming. Or second, they taught
programming like a mathematics textbook: all principles and concepts with little application
given to the reader. This book takes a different approach: show the source code for games right
up front and explain programming principles from the examples.

I’ve also made this book available under the Creative Commons license, which allows you to
make copies and distribute this book (or excerpts) with my full permission, as long as attribution
to me is left intact and it is used for noncommercial purposes. (See the copyright page.) I want to
make this book a gift to a world that has given me so much.

What’s New in the 3rd Edition?


The third edition features no new content since the second edition. However, the third edition has
been streamlined to cover the same content with 20% fewer pages. Explanations have been
expanded where needed and ambiguities clarified.

Chapter 9 was split into chapters 9 and 9½ to keep the chapter numbering the same.

The source code has intentionally been kept the same as the second edition to prevent confusion.
If you’ve already read the second edition, there’s no reason to read this book. However, if you are
new to programming, or introducing a friend to programming, this third edition will make the
process easier, smoother, and more fun.

Post questions to http://invpy.com/forum


Who is this book for?
Programming isn’t hard. But it is hard to find learning materials that teach you to do interesting
things with programming. Other computer books go over many topics most newbie coders don’t
need. This book will teach you how to program your own computer games. You’ll learn a useful
skill and have fun games to show for it! This book is for:

 Complete beginners who want to teach themselves computer programming, even if they
have no previous experience programming.
 Kids and teenagers who want to learn programming by creating games.
 Adults and teachers who wish to teach others programming.
 Anyone, young or old, who wants to learn how to program by learning a professional
programming language.
vi http://inventwithpython.com

TABLE OF CONTENTS
Chapter 1 - Installing Python ........................................................................................................... 1
Downloading and Installing Python ............................................................................................. 2
Starting IDLE ............................................................................................................................... 3
How to Use this Book .................................................................................................................. 4
Finding Help Online .................................................................................................................... 5
Chapter 2 - The Interactive Shell ..................................................................................................... 6
Some Simple Math Stuff .............................................................................................................. 6
Evaluating Expressions ................................................................................................................ 8
Storing Values in Variables ......................................................................................................... 9
Chapter 3 - Writing Programs ........................................................................................................ 14
Strings ........................................................................................................................................ 14
String Concatenation.................................................................................................................. 15
Writing Programs in IDLE’s File Editor.................................................................................... 15
Hello World! .............................................................................................................................. 16
Saving Your Program ................................................................................................................ 17
Opening The Programs You’ve Saved....................................................................................... 18
How the “Hello World” Program Works ................................................................................... 20
Variable Names .......................................................................................................................... 22
Chapter 4 - Guess the Number ....................................................................................................... 24
Sample Run of Guess the Number ............................................................................................. 24
Source Code of Guess the Number ............................................................................................ 25
import statements ................................................................................................................... 26
The random.randint() Function....................................................................................... 27
Loops ......................................................................................................................................... 29
Blocks ........................................................................................................................................ 29
The Boolean Data Type ............................................................................................................. 30

Post questions to http://invpy.com/forum


Comparison Operators ............................................................................................................... 30
Conditions .................................................................................................................................. 31
The Difference Between = and == ............................................................................................ 32
Looping with while statements ............................................................................................... 33
Converting Values with the int(), float(), and str() Functions .................................. 34
if statements ............................................................................................................................. 36
Leaving Loops Early with the break statement....................................................................... 37
Flow Control Statements............................................................................................................ 39
Chapter 5 - Jokes............................................................................................................................ 41
Making the Most of print() .................................................................................................. 41
Sample Run of Jokes .................................................................................................................. 41
Source Code of Jokes ................................................................................................................. 41
Escape Characters ...................................................................................................................... 42
Quotes and Double Quotes ........................................................................................................ 43
print()’s end Keyword Argument....................................................................................... 44
Chapter 6 - Dragon Realm ............................................................................................................. 46
Functions .................................................................................................................................... 46
How to Play Dragon Realm ....................................................................................................... 46
Sample Run of Dragon Realm ................................................................................................... 47
Source Code of Dragon Realm .................................................................................................. 47
def Statements .......................................................................................................................... 48
Boolean Operators ..................................................................................................................... 50
Return Values............................................................................................................................. 54
Global Scope and Local Scope .................................................................................................. 55
Parameters .................................................................................................................................. 56
Designing the Program .............................................................................................................. 60
Chapter 7 - Using the Debugger .................................................................................................... 62
Bugs! .......................................................................................................................................... 62
The Debugger............................................................................................................................. 63
viii http://inventwithpython.com

Stepping ..................................................................................................................................... 65
Find the Bug............................................................................................................................... 68
Break Points ............................................................................................................................... 71
Example Using Break Points ..................................................................................................... 72
Chapter 8 - Flow Charts ................................................................................................................. 75
How to Play Hangman ............................................................................................................... 75
Sample Run of Hangman ........................................................................................................... 75
ASCII Art ................................................................................................................................... 77
Designing a Program with a Flowchart...................................................................................... 77
Creating the Flow Chart ............................................................................................................. 79
Chapter 9 - Hangman ..................................................................................................................... 88
Source Code of Hangman .......................................................................................................... 88
Multi-line Strings ....................................................................................................................... 92
Constant Variables ..................................................................................................................... 93
Lists ............................................................................................................................................ 93
Methods ..................................................................................................................................... 97
The lower() and upper() String Methods ......................................................................... 98
The reverse() and append() List Methods.................................................................... 100
The split() List Method ..................................................................................................... 100
The range() and list() Functions................................................................................... 103
for Loops ............................................................................................................................... 104
Slicing ...................................................................................................................................... 106
elif (“Else If”) Statements .................................................................................................... 109
Chapter 9 ½ - Extending Hangman .............................................................................................. 117
Dictionaries .............................................................................................................................. 118
The random.choice() Function ....................................................................................... 121
Multiple Assignment ................................................................................................................ 122
Chapter 10 - Tic Tac Toe ............................................................................................................. 125
Sample Run of Tic Tac Toe ..................................................................................................... 125

Post questions to http://invpy.com/forum


Source Code of Tic Tac Toe .................................................................................................... 127
Designing the Program ............................................................................................................ 131
Game AI ................................................................................................................................... 133
References ................................................................................................................................ 138
Short-Circuit Evaluation .......................................................................................................... 146
The None Value ...................................................................................................................... 149
Chapter 11 - Bagels ...................................................................................................................... 157
Sample Run of Bagels .............................................................................................................. 157
Source Code of Bagels ............................................................................................................. 158
The random.shuffle() Function..................................................................................... 161
Augmented Assignment Operators .......................................................................................... 163
The sort() List Method ....................................................................................................... 164
The join() String Method .................................................................................................... 165
String Interpolation .................................................................................................................. 167
Chapter 12 - Cartesian Coordinates ............................................................................................. 171
Grids and Cartesian Coordinates.............................................................................................. 171
Negative Numbers ................................................................................................................... 173
Math Tricks .............................................................................................................................. 175
Absolute Values and the abs() Function .............................................................................. 177
Coordinate System of a Computer Screen ............................................................................... 178
Chapter 13 - Sonar Treasure Hunt ............................................................................................... 179
Sample Run of Sonar Treasure Hunt ....................................................................................... 180
Source Code of Sonar Treasure Hunt ...................................................................................... 183
Designing the Program ............................................................................................................ 188
An Algorithm for Finding the Closest Treasure Chest ............................................................ 195
The remove() List Method .................................................................................................. 197
Chapter 14 - Caesar Cipher .......................................................................................................... 207
Cryptography ........................................................................................................................... 207
The Caesar Cipher.................................................................................................................... 208
x http://inventwithpython.com

ASCII, and Using Numbers for Letters ................................................................................... 209


The chr() and ord() Functions .......................................................................................... 210
Sample Run of Caesar Cipher .................................................................................................. 211
Source Code of Caesar Cipher ................................................................................................. 212
How the Code Works ............................................................................................................... 213
The isalpha() String Method ............................................................................................ 215
The isupper() and islower() String Methods.............................................................. 216
Brute Force............................................................................................................................... 218
Chapter 15 - Reversi .................................................................................................................... 222
Sample Run of Reversi ............................................................................................................ 224
Source Code of Reversi ........................................................................................................... 227
How the Code Works ............................................................................................................... 235
The bool() Function............................................................................................................. 244
Chapter 16 - Reversi AI Simulation............................................................................................. 258
Making the Computer Play Against Itself................................................................................ 259
Percentages .............................................................................................................................. 263
The round() function ........................................................................................................... 264
Sample Run of AISim2.py ....................................................................................................... 265
Comparing Different AI Algorithms........................................................................................ 266
Chapter 17 - Graphics and Animation ......................................................................................... 274
Installing Pygame..................................................................................................................... 274
Hello World in Pygame ........................................................................................................... 275
Source Code of Hello World.................................................................................................... 275
Running the Hello World Program .......................................................................................... 277
Tuples....................................................................................................................................... 278
RGB Colors.............................................................................................................................. 279
Fonts, and the pygame.font.SysFont() Function ........................................................ 280
Attributes ................................................................................................................................. 282
Constructor Functions .............................................................................................................. 283

Post questions to http://invpy.com/forum


Pygame’s Drawing Functions .................................................................................................. 283
Events and the Game Loop ...................................................................................................... 288
Animation ................................................................................................................................ 289
Source Code of the Animation Program .................................................................................. 289
How the Animation Program Works ....................................................................................... 292
Running the Game Loop .......................................................................................................... 295
Chapter 18 - Collision Detection and Keyboard/Mouse Input ..................................................... 300
Source Code of the Collision Detection Program .................................................................... 300
The Collision Detection Algorithm.......................................................................................... 304
Don’t Add to or Delete from a List while Iterating Over It ..................................................... 309
Source Code of the Keyboard Input Program .......................................................................... 310
The colliderect() Method.............................................................................................. 318
Chapter 19 - Sounds and Images.................................................................................................. 319
Sound and Image Files ............................................................................................................. 320
Sprites and Sounds Program .................................................................................................... 321
Source Code of the Sprites and Sounds Program .................................................................... 321
The pygame.transform.scale() Function ................................................................. 325
Chapter 20 - Dodger..................................................................................................................... 329
Review of the Basic Pygame Data Types ................................................................................ 329
Source Code of Dodger ............................................................................................................ 330
Fullscreen Mode....................................................................................................................... 339
The Game Loop ....................................................................................................................... 343
Event Handling ........................................................................................................................ 343
The move_ip() Method ....................................................................................................... 346
The pygame.mouse.set_pos() Function ...................................................................... 349
Modifying the Dodger Game ................................................................................................... 353
Chapter 1 – Installing Python 1

Chapter 1
INSTALLING PYTHON
Topics Covered In This Chapter:
 Downloading and installing the Python interpreter
 How to use this book
 The book’s website at http://inventwithpython.com

Hello! This book teaches you how to program by making video games. Once you learn how the
games in this book work, you’ll be able to create your own games. All you’ll need is a computer,
some software called the Python interpreter, and this book. The Python interpreter is free to
download from the Internet.

When I was a kid, a book like this one taught me how to write my first programs and games. It
was fun and easy. Now as an adult, I still have fun programming and I get paid for it. But even if
you don’t become a computer programmer when you grow up, programming is a useful and fun
skill to have.

Computers are incredible machines, and learning to program them isn’t as hard as people think. If
you can read this book, you can program a computer. A computer program is a bunch of
instructions that the computer can understand, just like a storybook is a bunch of sentences
understood by the reader. Since video games are nothing but computer programs, they are also
made up of instructions.

To instruct a computer, you write a program in a language the computer understands. This book
teaches a programming language named Python. There are many different programming
languages including BASIC, Java, JavaScript, PHP, and C++.

When I was a kid, BASIC was a common first language to learn. However, new programming
languages such as Python have been invented since then. Python is even easier to learn than
BASIC! But it’s still a serious programming language used by professional programmers. Many
adults use Python in their work and when programming for fun.

The games you’ll create from this book seem simple compared to the games for Xbox,
PlayStation, or Nintendo. These games don’t have fancy graphics because they’re meant to teach
coding basics. They’re purposely simple so you can focus on learning to program. Games don’t
have to be complicated to be fun.
2 http://inventwithpython.com

Downloading and Installing Python


You’ll need to install software called the Python interpreter. The interpreter program
understands the instructions you’ll write in the Python language. I’ll just refer to “the Python
interpreter software” as “Python” from now on.

Important Note! Be sure to install Python 3, and not Python 2. The programs in
this book use Python 3, and you’ll get errors if you try to run them with Python 2.
It is so important I’ve added a cartoon penguin in Figure 1-1 to tell you to install
Python 3 so you do not miss this message.

Figure 1-1: An incongruous penguin tells you to install Python 3.

On Windows, download the Python installer (the filename will end with .msi) and double-click it.
Follow the instructions the installer displays on the screen to install Python, as listed here:

1. Select Install for All Users and then click Next.

2. Install to the C:\Python34 folder by clicking Next.

3. Click Next to skip the Customize Python section.

On Mac OS X, download the .dmg file that’s right for your version of OS X from the website and
double-click it. Follow the instructions the installer displays on the screen to install Python, as
listed here:

1. When the DMG package opens in a new window, double-click the Python.mpkg file. You
may have to enter the administrator password.

2. Click Continue through the Welcome section and click Agree to accept the license.

Post questions to http://invpy.com/forum


Chapter 1 – Installing Python 3

3. Select HD Macintosh (or whatever name your hard drive has) and click Install.

If you’re running Ubuntu, you can install Python from the Ubuntu Software Center by following
these steps:

1. Open the Ubuntu Software Center.

2. Type Python in the search box in the top-right corner of the window.

3. Select IDLE (using Python 3.4), or whatever is the latest version.

4. Click Install. You may have to enter the administrator password to complete the
installation.

Starting IDLE
IDLE stands for Interactive DeveLopment Environment. The development environment is like
word processing software for writing Python programs. Starting IDLE is different on each
operating system.

On Windows, click the Start button in the lower left corner, type “IDLE” and select IDLE
(Python GUI).

On Mac OS X, open the Finder window and click on Applications. Then click Python 3.4. Then
click the IDLE icon.

On Ubuntu or Linux, open a terminal window and then type “idle3”. You may also be able to
click on Applications at the top of the screen. Then click Programming and IDLE 3.

The window that appears when you first run IDLE is the interactive shell, as shown in Figure 1-
2. You can enter Python instructions into the interactive shell at the >>> prompt and Python will
perform them. After displaying instruction results, a new >>> prompt will wait for your next
instruction.

Figure 1-2: The IDLE program’s interactive shell on Windows, OS X, and Ubuntu Linux.
4 http://inventwithpython.com

How to Use this Book


Most chapters in this book will begin with a sample run of the chapter’s featured program. This
sample run shows you what the program looks like when you run it. The parts the user types in
are shown as bold print.

Type the code for the program into IDLE’s file editor yourself, rather than download or
copy/paste it. You’ll remember programming better if you take the time to type in the code.

Line Numbers and Spaces


When typing the source code from this book, do not type the line numbers at the start of each
line. For example, if you see this in the book:

9. number = random.randint(1, 20)

You do not need to type the “9.” on the left side, or the one space immediately following it. Just
type it like this:

number = random.randint(1, 20)

Those numbers are there only so that this book can refer to specific lines in the program. They are
not a part of the actual program’s source code.

Aside from the line numbers, enter the code exactly as it appears. Notice that some of the lines of
code are indented by four or eight spaces. Each character in IDLE is the same width, so you can
count the number of spaces by counting the number of characters on the line above or below.

For example, the indented spaces here are marked with a ▪ black square so you can see them:

while guesses < 10:


▪▪▪▪if number == 42:
▪▪▪▪▪▪▪▪print('Hello')

Text Wrapping in This Book


Some instructions are too long to fit on one line on the page and will wrap around to the next line.
When you type this code, enter it all on one line without pressing ENTER. You can tell when a
new instruction starts by looking at the line numbers on the left. The example below has only two
instructions:

1. print('This is the first instruction! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


xxxxxxxxxxxx')

Post questions to http://invpy.com/forum


Chapter 1 – Installing Python 5

2. print('This is the second instruction, not the third instruction.')

The first instruction wraps around and makes it look like three instructions in total. That’s only
because this book’s pages aren’t wide enough to fit the first instruction on one line.

Finding Help Online


This book’s website is at http://inventwithpython.com. You can find several resources related to
this book there. Several links in this book use the invpy.com domain name for shortened URLs.

The website at http://reddit.com/r/inventwithpython is a great place to ask programming questions


related to this book. Post general Python questions to the LearnProgramming and LearnPython
websites at http://reddit.com/r/learnprogramming and http://reddit.com/r/learnpython,
respectively.

You can also email me your programming questions at [email protected].

Keep in mind there are smart ways to ask programming questions that help others help you. Be
sure to read the Frequently Asked Questions sections these websites have about the proper way to
post questions. When asking programming questions, do the following:

 If you are typing out the programs in this book but getting an error, first check for typos
with the online diff tool at http://invpy.com/diff. Copy and paste your code into the diff
tool to find any differences from the book’s code in your program.
 Explain what you are trying to do when you explain the error. This will let your helper
know if you are on the wrong path entirely.
 Copy and paste the entire error message and your code.
 Search the Web to see whether someone else has already asked (and answered) your
question.
 Explain what you’ve already tried to do to solve your problem. This tells people you’ve
already put in some work to try to figure things out on your own.
 Be polite. Don’t demand help or pressure your helpers to respond quickly.

Asking someone, “Why isn’t my program working?” doesn’t tell them anything. Tell them what
you are trying to do, the exact error you are getting, and your operating system and version.
6 http://inventwithpython.com

Chapter 2
THE INTERACTIVE SHELL
Topics Covered In This Chapter:
 Integers and Floating Point Numbers
 Expressions
 Values
 Operators
 Evaluating Expressions
 Storing Values in Variables

Before you can make games, you need to learn a few basic programming concepts. You won’t
make games in this chapter, but learning these concepts is the first step to programming video
games. You’ll start by learning how to use Python’s interactive shell.

Some Simple Math Stuff


Open IDLE using the steps in Chapter 1, then get Python to solve some simple math stuff. The
interactive shell can work just like a calculator. Type 2 + 2 into the interactive shell at the >>>
prompt and press the ENTER key on your keyboard. (On some keyboards, this is the RETURN key.)
Figure 2-1 shows how the interactive shell responds with the number 4.

Figure 2-1: Enter 2+2 into the interactive shell.

This math problem is a simple programming instruction. The + sign tells the computer to add the
numbers 2 and 2. Table 2-1 lists the other math symbols available in Python. The - sign will
subtract numbers. The * asterisk will multiply numbers. The / slash will divide numbers.

Post questions to http://invpy.com/forum


Chapter 2 – The Interactive Shell 7

Table 2-1: The various math operators in Python.


Operator Operation
+ addition
- subtraction
* multiplication
/ division

When used in this way, +, -, *, and / are called operators. Operators tell Python what to do with
the numbers surrounding them.

Integers and Floating Point Numbers


Integers (or ints for short) are whole numbers such as 4, 99, and 0. Floating point numbers (or
floats for short) are fractions or numbers with decimal points like 3.5, 42.1 and 5.0. In Python,
the number 5 is an integer, but 5.0 is a float. These numbers are called values.

Expressions
These math problems are examples of expressions. Computers can solve millions of these
problems in seconds. Expressions are made up of values (the numbers) connected by operators
(the math signs). Try entering some of these math problems into the interactive shell, pressing the
ENTER key after each one.

2+2+2+2+2
8*6
10-5+6
2 + 2

After you type in the above instructions, the interactive shell will look like Figure 2-2.

Figure 2-2: What the IDLE window looks like after entering instructions.
8 http://inventwithpython.com

Figure 2-3: An expression is a made up of values and operators.

In the 2 + 2 example, notice that there can be any amount of spaces between the values
and operators. However, always start instructions at the beginning of the line when entering them
into the interactive shell.

Evaluating Expressions
When a computer solves the expression 10 + 5 and gets the value 15, it has evaluated the
expression. Evaluating an expression reduces the it to a single value, just like solving a math
problem reduces the problem to a single number: the answer. The expressions 10 + 5 and 10 + 3
+ 2 both evaluate to 15.

Expressions can be of any size, but they will always evaluate down to a single value. Even single
values are expressions: The expression 15 evaluates to the value 15. For example, the expression
8 * 3 / 2 + 2 + 7 - 9 will evaluate down to the value 12.0 through the following steps:

8 * 3 / 2 + 2 + 7 – 9

24 / 2 + 2 + 7 – 9

12.0 + 2 + 7 – 9

14.0 + 7 – 9

21.0 – 9

12.0

You don’t see all of these steps in the interactive shell. The interactive shell does them and just
shows you the results:

>>> 8 * 3 / 2 + 2 + 7 - 9
12.0

Post questions to http://invpy.com/forum


Another random document with
no related content on Scribd:
CHAPTER XIII
HERBERT MAKES A HIT AND TIDES OVER A TEMPORARY
FINANCIAL DIFFICULTY

Herbert was still young enough to be sensitive, and the thought that
his maiden effort in the big city had probably found its way into the
waste paper basket was galling to his natural pride. However, he
braced himself and called at the office at noon again, and smilingly
greeted his colleagues. He learned some things during the day, and
one was a conviction that success on a country newspaper did not
necessarily fit a man for immediate employment on a metropolitan
daily. He had a long and confidential talk with Frank Tomlin, during
the course of which he related his experience and the fate of his first
item.
Tomlin laughed heartily at the recital.
“You can’t afford to be thin-skinned in New York, my boy,” he
replied. “Besides, you are mistaken about your item. It was written
all right, but was crowded out in the make-up.”
“Do you think so?”
“I am satisfied of it. I have helped Blakeley to make up the paper on
more than one occasion, and there were times when stories bigger
and more important than yours and which were in type were thrown
aside for want of space. So don’t let a little thing like that trouble
you. Persevere; do the best you can, and don’t permit yourself to be
cast down by little incidents of this kind.”
Herbert thanked him for this friendly advice and promised to profit
by it. The talk caused Tomlin to drift into a train of reminiscences.
“I’ll never forget my first experience in the newspaper business in
this city,” he said musingly; “it satisfied me that enterprise, while
quite valuable in itself, is not the most important thing in the
gathering of news. I know that when I began I was eager to
accomplish great things.
“One morning the city editor assigned me to a meeting of the
Municipal League, and as I was leaving the room he called out:
“‘See here, I want you to put a little ginger in your articles. We want
to brighten the paper up a bit.’
“It was a prosy gathering. Most of the members of the league were
elderly or old men, and they made long winded speeches and
accomplished little business. There did not seem to be much
prospect of a bright article in the ordinary report of a meeting of this
character. I decided to burlesque the meeting. The result was all that
could be desired. The city editor was not ‘on’ and the story went
straight to the copy desk.
“The next morning I was informed the proprietor wanted to see me.
I felt at once that this summons had something to do with my
article. When I entered the room, he looked at me curiously and in
silence for some moments.
“‘Did you write the meeting of the Municipal League which appears
in this morning’s paper?’
“‘I did,’ I answered, swelling up with pride.
“He was silent.
“‘Didn’t you like the report?’ I finally inquired.
“‘Yes,’ he said, prolonging the word in a strange manner.
“‘Wasn’t it good enough?’ I inquired.
“‘Oh, yes,’ with a peculiar laugh; ‘it was bright.’ Then turning to me
he said impressively: ‘I have no doubt in the world that the members
of the league deserve all the ridicule you cast on them, but,’ he
added, ‘it should not have been printed in my paper. I am the
president of the Municipal League.’”
Herbert and Tomlin remained in conversation for a long while, and
the older man regaled his companion with a batch of very interesting
stories bearing upon the incidents that take place behind the scenes
of journalism. They walked home together that night, and Herbert,
feeling that Tomlin was a man in whom he could trust and confide,
confessed to him the low condition of his finances.
“I thought I would get immediate employment,” he said, “and as a
consequence brought only a small amount of money with me from
the country. I met an old acquaintance who was on his uppers and
gave him a large part of my surplus. As the result of this and my
other little expenditures, I have only about two dollars.”
“Do you want to borrow anything?” said the other, turning to him
quickly; “I will be glad to stake you if you do.”
“Not at all,” said Herbert hastily, “I hope you won’t think I introduced
the subject for that purpose. But it will be about ten days before I
receive my first pay; and in the meantime next week’s board bill will
be due and payable. I wondered whether I could not earn a little
money in the meantime.”
“Certainly,” said Tomlin; “it will give you an opportunity for showing
what is in you, too. The thing is easy enough. Write some space for
the Argus. Blakeley is always willing to accept a good story, and if
you can go out into this human whirlpool to-morrow and fish up
something a little bit out of the ordinary he will be only too glad to
print it, and pay you for it, too.”
The following day, acting on the suggestion of his friend, Herbert
made the rounds of the city hospitals. The usual routine stories
presented themselves at all of these institutions; but most of them
were covered by staff men, and for that reason were not available
for a special space-writer. While Herbert was pondering over what
was best to do under the circumstances, it suddenly dawned on him
that perhaps the obvious thing might make the best story after all.
Things that were happening every day in the week were looked
upon as being trite and trivial. If he could take one of these
incidents and lift it out of the rut and make it stand toweringly above
other incidents of a like character he would make a hit. To think was
to act. He went to the head keeper in the next hospital and asked to
look over the book of records. Among the items inscribed there was
one which told about a patient who had attempted suicide, but
whose life would be saved. Herbert asked whether he could obtain
the details of this story, and was told that if he applied to one of the
assistants in the main ward he might obtain some additional
information. He did obtain more facts, and he hurried to the office,
eager to write the story. The heading was “How a Trained Nurse
Defeated Death.”
The introduction described how a demure little nurse in the hospital
who looked as if she might weigh not more than one hundred
pounds, started on a walking match against death at five o’clock in
the evening, and finished at six o’clock in the morning—a winner.
The story went on and told how the ambulance had brought a
twenty-two year old girl to the hospital after she had swallowed
enough opium to send three or four strong men to their death. The
poor, misguided girl who had taken the poison on account of a case
of unrequited love, showed a strong desire to go to sleep. The little
nurse knew that if the girl closed her eyes they would never again
open in this world; so she tried to keep her awake by slapping her
on the back.
That method was not strenuous enough, so the long walk was
started. It was up and down the corridor of the receiving ward, and
out into the hall and the yard. Whenever the nurse became tired she
sat down to rest for a moment; but as soon as the girl nodded the
walk was resumed. All through the lonesome hours of the night this
unique feat of pedestrianism was continued. Daylight appeared, and
still the walk went on. Finally the clock struck six, and the two
women were still walking. Shortly after that the house physician
made his appearance, and giving the girl a careful examination,
pronounced her out of danger. Then, and not until then, the nurse
went to sleep, and even while Herbert was writing his picturesque
story she was still sleeping the sleep of the just and the brave.
His story made over a column in the Argus. It proved to be a
palpable hit. Blakeley, the city editor, who did not see it until he
picked up the paper the next morning, gloated over it with the glee
with which a miser examines a newly found diamond. He patted
Herbert on the back and said that if he continued to turn in stories
of that character his period of probation would be short indeed and
his permanence on the paper assured.
But the best feature of the incident, to Herbert’s mind, came on
Friday afternoon, when he called at the business office and received
a check for $8 for his piece of special reporting. This gave him a
total cash balance of $10 and enabled him to pay his board bill and
to look forward with confidence to the coming of his regular pay-
days.
CHAPTER XIV
IN WHICH HERBERT IS GIVEN AN UNUSUAL OPPORTUNITY
TO DISTINGUISH HIMSELF

After he had been on the Argus for about a month, Herbert felt
entirely at home. He managed to get along very smoothly with all
the members of the staff. Blakeley, the city editor, was especially
pleased with the new addition to his local force. He found that he
was punctual, industrious and anxious to do his work to the very
best of his ability. The other reporters at the same time looked on
him as an agreeable fellow who was willing to do them a good turn
whenever he had the chance to do so. At the end of his second
month on the paper he was gratified at the receipt of an unsolicited
increase in his salary. His particular friend on the Argus, Francis
Tomlin, obtained a promotion at the same time; and the two young
men put their heads together and decided to seek a pleasant room
near the office. After a search that consumed nearly all the idle
hours of a whole week, they finally obtained an apartment which
had the added advantage of a neat and well kept bath-room.
Herbert lost no time in removing his effects from the modest
quarters which he had occupied since his first arrival in New York.
The two young men were together very much, and the fact that they
were employed at night and had many hours of leisure during the
day gave them the chance of strolling about the city or seeking
amusements together at a time when most other men were busily
engaged in their trades and professions.
The new room, which was comfortably furnished in the first place,
rapidly grew more habitable through the skill and good taste of the
two reporters. The gift of a set of books from home first gave
Herbert the idea of accumulating a library. Tomlin joined with him,
and in a surprisingly short time they were the possessors of quite a
valuable little library which counted among its principal assets
several important books of reference.
One day Herbert was delighted to receive a visit from Mr. Anderson,
who had been his school-teacher for so many years in Cleverly. In
honor of the event he begged off from the office for the night, and
secured a similar privilege for Tomlin. The three men sat in the room
till long past midnight, chatting about books and newspapers and
other topics of a congenial nature. Mr. Anderson told the story of
“barring out day” at the school in Cleverly, and the recital was done
so well that it filled Tomlin with delight and caused him to laugh with
such heartiness that the tears fairly ran down his cheeks.
On another occasion a little later in the year Noah Brooks, the editor
of the Cleverly Banner, visited New York, and while in the city was
the guest of Herbert Harkins. The young man was very much
pleased at the thought of entertaining the veteran editor, who had
been such a good friend to him in Cleverly. He took Tomlin into his
confidence, and between them they planned a program which kept
Mr. Brooks engaged every minute of the day and night during his
four days’ stay in the metropolis. In fact Herbert exhausted his
resources in showing the visitor what he was pleased to call “the
time of his life.” As the three men walked along Broadway together,
Mr. Brooks looking up at the high buildings on either side of him,
said musingly:
“Herbert, it’s been over forty years since I visited this town before,
and I want to say that there have been many changes since then.”
“I should say so,” replied Herbert, with a laugh; “in fact, although I
have been here only a few months I can see changes that are going
on at the present time.”
“Yes, many changes,” assented the old editor, nodding his head in a
reflective manner; “and these changes are not only in the big
buildings, but in the big men. I may be mistaken, but I don’t think
you produce the kind of men that we had in the days when I was in
my prime. However, I won’t insist on that. It may simply be the
natural thought of every old man.”
“Who would you regard as the most conspicuous man that was here
when you visited the city last?” asked Herbert, anxious to draw upon
his friend’s inexhaustible fund of recollections.
“Well,” he replied, “that’s a pretty hard question to answer after all
these years; but I think that perhaps good old Horace Greeley was
the best of them all. When I was here last I met him in the flesh.
Now all that you have of him is that statue in front of the Tribune
Building and the memory of his honest, old fashioned life.”
The old gentleman sighed at this as if he were not quite sure that
the good old times would ever come again. Indeed he was a type of
man very similar to the famous editor, whom he was accustomed to
look upon as the greatest man of his day and generation. Mr. Brooks
was careless in his dress, quaint in his manner and unyielding in his
integrity. Tomlin enjoyed the visit of the country editor, if anything,
more than Herbert; and he was really sorry when the trip came to
an end, and he went with Herbert to the depot to bid good-by to the
whole-souled old man.
In the meantime Herbert continued to make satisfactory progress in
the Argus office. He was receiving all kinds of assignments now, and
he soon had the reputation of being a man who did his work
perfectly. More than this, he was marked down as a reliable reporter,
which is a very important thing on any newspaper. The city editor
felt that when an assignment was placed in his hand it was sure to
be covered and the copy turned in at the earliest possible moment.
One morning as they were leaving the house together, Tomlin said to
Herbert:
“Some day, old man, you will get a very big thing to do, and it may
be the means of either making or breaking you.”
The occasion came sooner than expected. That very morning the
city editor summoned Herbert to his private office, and said:
“See here, Harkins, I am going to give you a chance to show what
there is in you. I have here what I regard as a very delicate and
difficult piece of work. It requires perseverance, and I am willing to
give you the job if you will tell me that you will stick at it and never
quit until your efforts have been crowned with success. Can you give
me that promise?”
Herbert smiled at this vigorous presentation of the case, and said:
“Well, Mr. Blakeley, if it is a piece of newspaper work that comes
within my ability, I feel reasonably sure of coming out successful.”
“Well,” said the other, in his short, snappy tones, “here is a letter. It’s
a small clue as a starting point. Read it over, and then come back to
me.”
Herbert went to his desk and read the letter as directed. It was from
a poor woman who had been induced to send $2 of her hard earned
money to a concern which promised to teach her how to paint on
china within two weeks, and after that time to furnish her with
steady employment which would pay her anywhere from $10 to $20
a week, according to her speed and ability. She said in her letter that
she had sent the money, and in return received a flimsy circular
which gave some crude and utterly impracticable directions of how
to paint. The thing was worthless to her and her $2 wasted.
When Herbert had finished reading this, he returned to Blakeley and
said:
“Have you any further directions?”
“No,” was the reply, “you will have to work on your own resources
from now on. I suppose that eventually the postal authorities will
hear of this swindle and refuse to permit this sort of thing to go
through the mails; but in the meantime we know about it and we
want to get the credit of stopping it at once. You take the address of
this woman and go ahead and see what you can make of it.”
Herbert called upon the woman that afternoon, and in less than an
hour had obtained a very good story from her, backed up by a sworn
statement of her experience with the concern. At the same time he
learned the names and addresses of ten other persons who had
been swindled in a similar manner. Altogether four days were
consumed in visiting and interviewing these persons. Some of them
who had natural ability, had learned to paint on china in spite of the
bungling directions sent out by the concern; but when they wrote to
the company and asked for the employment that was to pay them
from $10 to $20 a week their letters were ignored. Altogether the
young reporter had what might be called a first class story. When he
had all of his facts in good shape he went to the city editor again,
and said:
“Mr. Blakeley, I want you to give me authority to employ a private
detective. I have everything in perfect condition at present, and all I
need is the climax, which I hope to bring about at noon to-morrow.
In other words, it is necessary to arrest someone connected with
this concern. If we do this, I will have plenty of witnesses, and we
can have the scoundrel held for court.”
“Capital! Capital!” shouted Blakeley. “I will give you the authority to
employ a detective at once. How do you propose going about it?”
“That is quite simple,” answered Herbert; “the company has a box in
the post office. I have sent a decoy letter, which should be placed in
the box between eleven and twelve o’clock to-morrow. They
probably employ a go-between, or a messenger, who gathers up the
letters and takes them to the head swindler. We must arrest this
person, whoever he is, and probably with a little ingenuity we may
be able to extort a confession from him, and then go after the other
fellows. In the meantime I am going back to my room and will start
to typewrite the story. I have it blocked out, so that we can make a
full page scare out of it. We ought to have a picture of the man who
comes after the letters, and then, if possible, a photograph of the
head swindler, and interviews with all the victims.”
Blakeley looked at the young man with admiration written in every
line of his countenance. He put out his short, pudgy hand, and
slapped Herbert on the back.
“Harkins, you are all right. You’ll do. Go ahead, my boy, and I wish
you luck in your undertaking.”
CHAPTER XV
IN WHICH HERBERT DOES SOME VERY HARD WORK AND
RECEIVES A TERRIBLE SHOCK

Herbert arose much earlier than usual the next morning, for he had
a keen appreciation of the important character of the work that lay
before him. He had hardly finished his breakfast when there was a
ring at the door and the landlady brought up a card which bore upon
its glazed surface the simple inscription “M. Short.” Herbert
wondered who this could be, but directed that he be sent up to his
room at once. A few minutes later he was greeting a short-set,
stockily-built man, with sharp eyes and a sad expression of
countenance.
“Well, Mr. Short,” said Herbert, “what can I do for you?”
The bright eyes of the little man twinkled merrily as he responded:
“I fear that I will have to put the shoe on the other foot and kindly
inquire what I can do for you.”
“Why,” said Herbert, “I never met you before.”
“Probably not,” replied the other, still smiling; “but I was ordered to
report to you this morning, and told that you would give me
directions how to proceed.”
“Oh!” exclaimed Herbert, a light breaking in on him, “you are the
detective.”
“Yes,” said the other mildly, “that is my business, and I am now at
your service.”
After a conversation of ten or fifteen minutes, the reporter and the
detective came to a thorough understanding. They were to meet at
the main post office shortly before noon, and their movements after
that were to depend entirely upon circumstances. Herbert was
pleased with the character of man who had been sent to assist him,
and mentally congratulated himself upon what now appeared to be
the certain success of many days of hard labor. The end was already
in view.
A few minutes after the detective had taken his leave, Herbert
received a square cornered envelope, containing his name and
address. He tore it open quickly and read as follows:
“Dear Herbert:
“Father, mother and I have removed to New York for the
winter, and would be glad to have you call at the earliest
opportunity. We understand that you are engaged in your
newspaper work in the evening, so that if you care you
are quite welcome to call in the morning, or at any other
time that may suit your convenience.
“Very sincerely yours,
“Mary Black.”
Herbert looked at his watch. He had nearly three hours to spare
before it would be time to keep his appointment with the detective
in the post office, and he quickly decided to utilize it by making a
hurried call on the Blacks. The address given was that of a house on
West 69th Street, and in a very short time, by making use of the
sub-way, Herbert found himself at the address indicated.
Mary Black, who responded to his call, was delighted to see her old
friend and schoolmate, and in a few minutes he was also talking
with Mr. and Mrs. Black. The family, distressed by the continued
absence of the son and brother, had determined to stay in New York
for some months in the hope of obtaining some clue to the runaway.
A financial friend of Mr. Black, who had gone to Europe for the
winter, had insisted upon his occupancy of the house during the time
that he was absent from the country. Although the suggestion had
been made only a fortnight before, the little family was already
comfortably installed in the 69th Street house. They were all
delighted with their new surroundings, and Mary was very much
pleased and interested with the sights of the big city; but over it all
there was a certain sadness caused by the sorrow which was felt on
account of the erring one. The father was almost completely crushed
at the domestic affliction which overshadowed their hearthstone. He
had lost the coldness and haughtiness for which he was
distinguished while at Cleverly, and in broken tones expressed to
Herbert the sorrow he felt at the injustice which he had done to his
old friend, David Harkins. He said that if an opportunity should ever
come whereby he would be enabled to remedy the ill that had been
caused through his thoughtless words, he would cheerfully do so.
Time passed so rapidly and so pleasantly in the company of Mary
Black that Herbert was loath to leave. A look at his watch, however,
showed that he had less than an hour before the time would arrive
for keeping his appointment, so he bade good-by to Mr. and Mrs.
Black and hurried towards the door. Mary accompanied him there,
and he noticed from her constrained manner that she had something
on her mind and was anxious to speak to him privately. Being a
man, he felt that it was incumbent upon him to break the ice, so he
said gently:
“Mary, is there anything I can do for you or your father or mother? If
so, don’t hesitate to speak to me frankly.”
“There is something, Herbert,” she said, “and it has been weighing
upon my mind for a long while. It is about Arthur. I want you to
promise me that you will be a friend to my brother. I do not believe
that he is a bad boy at heart; but unfortunately, he has fallen into
bad company and has been led astray. Promise me that if the
opportunity ever presents itself, you will give him a helping hand.
This chance may come, or it may never come; but tell me that you
will not forget what I have said to you.”
Herbert took her by the hand, and said with much solemnity:
“Mary, if I ever meet Arthur and have the opportunity of befriending
him, I promise you that I shall do so.”
Her eyelashes were wet with tears; but at his words, her eyes
sparkled with satisfaction, and she exclaimed eagerly:
“Oh, I thank you so much for saying that, because I know that I can
trust you, and I know that you mean what you say.”
A few minutes later Herbert was once more in the sub-way, speeding
towards the Park Row station, which was within a short distance of
the main post office building. He reached that busy spot at ten
minutes of twelve o’clock and found the detective awaiting him. The
two men held a hurried interview with the clerk of the box
department, who informed them that he knew the young man who
was in the habit of calling for the letters for the swindling concern
which they now had under suspicion. He said that he would remain
at his post for the next fifteen or twenty minutes and as soon as he
identified the fellow he would give the two men a signal by holding
up his right hand. The details of the plan having been arranged, the
reporter and the detective set themselves to wait for the critical
moment. It proved to be a great strain on all concerned. The hands
of the big clock moved around so slowly that they could almost have
shrieked out with impatience and anxiety. A great crowd was
hurrying to and fro and opening and closing the letter boxes, which
reached almost from the pavement to the ceiling all along the great
corridor, but the moments dragged by and the clerk had made no
signal.
Presently a man wearing a long ulster and a derby hat stooped down
on one knee and began opening the letter box which contained the
mail belonging to the china painting concern. He entered so quickly
that neither Herbert nor the detective caught a glimpse of his face.
The box clerk inside the office became very much excited when the
man stooped down, and getting a good look at his face, raised his
hand and shook it in the air as a signal to those on the outside. It
said just as clearly as if the words had been spoken:
“There is your man. Nab him.”
The detective moved to one side so that he could arrest his man the
minute he arose from his sitting position. Herbert, who was
becoming quite nervous from the strain, motioned the detective to
step back a few yards. When this had been done, the young reporter
got immediately in the rear of the kneeling man so that when he
arose he could face him and make his accusation as dramatically as
possible. He felt that this was to be a great occasion in his
journalistic life, and he wanted it to come off successfully and
without the slightest slip.
The man in the ulster was terribly slow about his work. His head and
his face were so close to the box that it was impossible to get a
glimpse of his countenance. Besides he fingered each letter
separately as if to feel and mentally calculate the amount of money
enclosed in each of the envelopes. The action did not escape
Herbert’s attention, and caused him to curl his lips up in a look of
unutterable scorn.
“Calculating his stealings,” he muttered to himself indignantly;
“considering how much money he has filched from poor girls and
women who have scarcely enough to buy food to eat.”
The kneeling figure, however, knew nothing of the contempt with
which he was being regarded by the warm-blooded young man
behind him. Presently he finished his examination of the letters and
had put them all in the little leather gripsack which he had beside
him. He arose very slowly, and then turned around and came face to
face with the young reporter.
The sight that met the gaze of Herbert Harkins caused him to
become as pale as a sheet. His head seemed to be reeling around
him, and he felt as if he could scarcely stand without support.
He looked again. The second glance only confirmed what he had
seen at first.
The youth who stood before him was Arthur Black!
CHAPTER XVI
IN WHICH HERBERT LOSES HIS POSITION AND RETIRES IN
DISGRACE

The shock of discovering Arthur Black so unexpectedly and under


such damaging circumstances completely unnerved Herbert Harkins.
For many seconds he stood there staring at Arthur as if he were
some ghostly phantom who had suddenly appeared from the grave.
By degrees Herbert began to realize the compromising position in
which he had placed himself. The detective stood only a few yards
away eagerly watching the scene and awaiting the moment when he
would be called upon to place Arthur Black under arrest. Herbert did
not turn around, but felt that the sleuth was there, ready to perform
the act which was to be the capstone of a remarkably clever piece of
newspaper work.
In that brief period of time his mind traveled with lightning like
rapidity. He thought of his troubles in the country. He remembered
the incident when he had punished Arthur. He recalled the
threatened disgrace which had preceded his father’s sudden death.
He remembered his work on the Cleverly Banner, and then by easy
stages his mind reverted to his arrival in New York, his employment
on the Argus, and finally to his meeting with Mary Black on that very
morning. He thought of Blakeley, the city editor, impatiently waiting
for the announcement that his big story was to be a success and
that the Argus could pride itself not only upon a notable scoop, but
also upon the exposure of a set of swindlers who had preyed
remorselessly upon the public.
What should he do? His duty seemed clear and unavoidable. Surely
one would have to suffer for the benefit of the many. Besides that
the eyes of the detective were upon him, and his failure to do the
right thing at this moment might lead to his complete downfall. From
this thought his mind reverted to every detail of the impressive
interview which he had held with Mary Black a little more than an
hour before. A voice within him urged him to be faithful to his
promise, no matter what personal loss he might suffer. He had given
her his pledge that if he ever met Arthur Black he would lend him a
helping hand; that if he was in trouble he would succor him; that if
he was in danger he would save him. For what seemed to be a very
long time he was torn with conflicting emotions. Many minutes
seemed to elapse—in reality it was only a few seconds. He reached
his decision quickly, and he acted promptly. Putting his arm on
Arthur’s shoulder, he whispered, almost hissed, into the latter’s ear:
“You are on the verge of ruin. I have been sent here to arrest you. A
detective is standing a few yards away. If you wish to avoid arrest,
exposure and disgrace, run—run for your life.”
Arthur clutched convulsively at the grip in his right hand and gave a
hurried look about him. His glance fell upon the short, stockily built
man with the little twinkling eyes, who stood only a few yards
distant. Some instinct seemed to tell Arthur that this was the
detective, that this was the one man he should avoid. As quick as
thought, he turned on his heel and made a dash in the opposite
direction. The detective noting the movement, started to follow him;
but Herbert shouldering his way against some people who were
standing between them, got in front of the detective and completely
blocked his way.
“Move aside,” said the officer angrily, “don’t you see that that fellow
is getting away? Move aside, I tell you!”
By this time the crowd in the corridor had become so dense that it
was almost impassable. It was quite evident that Arthur had made
his escape and in all probability was now out of harm’s way. Herbert
turned to the detective and said in a low tone:
“It’s the wrong fellow, old man; it’s all a mistake.”
The little twinkling eyes looked searchingly into Herbert’s face. What
he saw there satisfied him. The pale face, the look of despair, the
nervous manner were sufficient to indicate that the young man had
just passed through a crisis. It would be useless to argue with him.
The detective did not attempt it. He buttoned up his coat, pulled his
hat down more firmly over his head, and walked away, muttering:
“Well, this is the queerest game I’ve ever been up against in all my
career.”
After the detective left him, Herbert moved over to one of the big
windows in the post office corridor, and leaning his elbows on the
sill, stood there for some time musing upon the incidents that had
just occurred. He recalled with a feeling of sadness Tomlin’s
prophetic words: “An opportunity may come to you to do some big
bit of work, and it will either break you or make you.”
The opportunity had come much quicker than he had anticipated,
and unless all signs failed it would prove to be the cause of his
undoing. He wondered in a numb sort of way how he was ever
going to face Blakeley. He had started out on this assignment with a
great display of enthusiasm. Indeed, now that he looked back upon
it he had acted with considerable presumption. He had as good as
boasted of the ease with which he intended to handle the case, and
now it was all ended in an inglorious fizzle. The thought of a face to
face encounter with Blakeley was decidedly chilling. Blakeley, while
possessing many charming personal traits, was one of the hardest
taskmasters in the office. Herbert shrank at the thought of going
before him without the coveted story. He even contemplated the
notion of not returning to the office at all; but this bit of cowardice
was soon overcome as a thought not to be seriously considered for
an instant. He would return to the office; he would face the music
like a man; and he would take his medicine—no matter how bitter—
without making any faces.
He left the post office building to go to the Argus office; but
somehow or other he could not summon up sufficient courage to
undergo the dreadful ordeal; so he walked up Broadway, mingling
with the crowd, looking in the shop windows and trying to forget the
terrible details of the most unpleasant incident of his life. After
awhile he turned off Broadway and walked in the direction of Fifth
Avenue. When he had reached that fashionable thoroughfare he
bent his footsteps towards Central Park. By this time it was late in
the afternoon. The fashionable turnouts of the rich and the
prosperous were going up the avenue, skilfully guided through the
crowded street by richly liveried drivers who seemed to know every
inch of the ground. Still Herbert walked on and on, seemingly
unconscious of what he was doing. The approach of dusk brought
him to his senses. He must go to the office and go there as quickly
as possible.
He jumped on a ’bus that was going down-town, and at the
intersection where the Avenue joins Broadway he alighted and
boarded one of the surface cars. It was quite dusk when he reached
the Argus office, and walking into the local room in an uncertain
manner, he noticed that most of the men were out and that Blakeley
was seated at his desk alone. The city editor was puffing at a big
cigar, and did not notice the entrance of the young reporter.
Herbert was the first to speak.
“Mr. Blakeley,” he said, in a hushed sort of voice.
The city editor turned around like a flash.
“Hello there, Harkins,” he said eagerly; “I’ve been waiting for you all
the afternoon. How did the thing pan out?”
“It didn’t pan out at all,” said Herbert in a hesitating, halting way.
“What do you mean?” cried the other, his tone perceptibly
hardening.
“I mean that I have no story,” this in a slightly firmer voice.
“No story?” shouted the other, “why what are you talking about
anyhow? There must be a story.”
“There was a story,” rejoined Herbert, now throwing all precaution to
the winds; “but I can’t write it.”
“Can’t write it? Why, you’re crazy, man. What are you talking about?”
The city editor was thoroughly angry now. He arose from his chair
and stood towering before Herbert. In his rage he threw his freshly
lighted cigar into the cuspidor with a savage movement of his hand.
He stamped his foot on the floor fiercely.
“There is no use talking about this matter any longer. You go to your
desk and write this thing and have your copy ready as soon as
possible.”
“I can’t write it,” said Herbert, now speaking in a voice that was
scarcely audible.
Blakeley was silent, trying hard to control his rising passion. When
he spoke his voice sounded almost like a hiss.
“You understand what this means, don’t you—you know what it will
cost you?”
“Yes,” said Herbert, looking up; “I understand, and I resign my
position as a reporter on the Argus.”
“Your resignation is accepted,” said the other shortly; “but I call
upon you to do the work that you were assigned to perform, before
leaving this office.”
“I can’t do it,” said Herbert; “on my honor I cannot do it.”
“But what explanation have you to give?”
Herbert looked up helplessly. For a moment a desire to tell the whole
story to Blakeley took possession of him. The next minute it was
dismissed as impracticable. Blakeley was a man without any heart or
feeling. He felt convinced of this, and felt likewise that if the facts
were once in the city editor’s possession the story would have to be
written regardless of the private anguish it might cause. So he stood
there speechless before his superior.
“Go!” finally shouted Blakeley, pointing to the door. “But when you
go remember that you go in disgrace. You are like an engineer who
would leave his train in the middle of the journey, or a pilot who
would desert his ship in a storm at sea. Go, and never let me see
you again.”
Herbert left the room with a flushed face and downcast eyes. He
avoided the elevator. The thought of meeting with anyone at a time
like this grated upon his feelings. He walked down the stairway with
a heart as heavy as lead. He felt mortified and angry by turns. He
mentally blamed Blakeley for his coarse manner and the ugly
scolding he had given him. The next second he admitted to himself
that Blakeley was fully justified in what he had said and done.
Indeed, from the standpoint of the news and of duty, he could find
no possible justification for his own conduct.
Presently he got out into Park Row and was soon in the midst of the
pushing, bustling crowd. It was quite dark now, and the rush to the
bridge was at its height. Myriads of electric lights shone brightly all
about him. Cars rushed by, with motormen sounding their gongs
continuously. Wagon drivers shouted and shrieked and pulled at
their horses, and thousands of pedestrians laughed and shouted as
they hurriedly went their way. Herbert, in a vague sort of way,
wondered how they could all be so happy when he felt so miserable.
Nothing seemed the same to him. Some mysterious change
appeared to have overcome the face of New York since he had left
his home early that morning; but in reality things moved on as
before. Herbert’s philosophy did not realize that the world moves on
day by day and night by night, regardless of the joys or the woes of
the individual.
He soon reached his lodgings and quietly let himself in the door by
means of his latch-key. He struck a light and gazed about curiously
at the familiar things in the little apartment. Everything in the room
seemed to look at him in a reproachful manner. Strange as it may
seem, it was some moments before he became accustomed to being
alone. Then he picked up a book and tried to read; but it was a
dismal failure. He walked the floor for a long, long while. There was
a lump in his throat that he could not remove. Presently he sank
down into a chair and dropped his bowed head into his hands on the
table.
“I’ve lost my job,” he groaned to himself. “I’ve done more than that.
I’ve not only lost my place, but I’ve been retired in disgrace.”
CHAPTER XVII
THE YOUNG REPORTER FINDS THAT THE DOOR OF
OPPORTUNITY IS BARRED TO HIM

Herbert sat in the darkened room with his head bowed on the table
for a very long while, thinking of the events that had taken place the
previous twenty-four hours. First he was angry with himself for what
he had done, and then felt humiliated at permitting Blakeley to
abuse him in such a cruel manner; but with second thought came
the conviction that even if he had it to go over again he would not
have acted in a different manner. To have written the story even
with Arthur at liberty would have meant lasting disgrace to Mary
Black and her parents. He had paid a very dear price, but had
averted that, which after all, was a very consoling thing. While he
sat there Tomlin came into the room in his impetuous manner. He
rushed over to Herbert and clapped him on the shoulders.
“Brace up, old man; don’t sit here and mope as if you had lost your
last friend in the world.”
Herbert looked up at him and tried to smile; but the effort was a
very sickly one.
Tomlin sat down beside his friend, and becoming serious, said:
“See here, old chap, I don’t want to pry into your affairs, but why in
the world did you throw Blakeley down in that cold-blooded
fashion?”
“I didn’t throw Blakeley down,” began Herbert angrily.
But the other man held up his hand to stay the hot words, and
replied in a low voice:
“But you did throw him down, and there is no possible way of
proving anything to the contrary. Now you must have had a reason,
and if you care to give it to me, I’ll be glad to listen.”
“I hope you won’t consider me rude, or lacking in friendship,” replied
Herbert; “but really the circumstances make it impossible for me to
tell you why I acted as I did.”
“All right, old fellow,” rejoined Tomlin, slapping Herbert on the back
again; “I am satisfied whether you tell me or not. I believe in you
and that is sufficient.”
Shortly before noon the following day Herbert went to the office of
the New York Sentinel and presented his card to the city editor. That
individual sat in his roll-top chair and gazed at the bit of pasteboard
musingly:
“So you want a job, do you? Well, I have heard of your name before,
and I understand that you have done some creditable work. I might
make a place for you here—”
“Could you?” inquired Herbert eagerly; “I’m sure if you would give
me the chance I’d make good.”
“I don’t doubt it,” said the city editor. Then as if the thought had just
struck him: “By the way, how did you come to leave the Argus?”
Herbert flushed up at this, and the fact did not escape the attention
of the keen-witted city editor of the Sentinel. He scrutinized his
visitor with a steady eye. Herbert hesitated for some seconds, and
then said slowly:
“Well, to tell the truth, that is a personal matter that I cannot
explain.”
“All right,” said the other slowly, “that rests with you entirely.”
“Can I have the position?” inquired Herbert.
“Well,” said the other, rubbing his hand over his face and speaking
slower than before, “I think you had better come in and see me
again in the course of a day or so.”
This was not very satisfactory, but Herbert had to make the best of
it. He returned to his room for the purpose of writing some letters
and later on took a walk. Two days after this incident he called at
the Sentinel office, but found, to his disappointment, that the city
editor was out of the city. Another day elapsed, and this time the
man he was in search of was at his desk.
“Do you find that you will be able to employ me on the Sentinel?”
asked Herbert.
“No,” said the city editor decidedly; “no, I cannot find room for you.”
“Is there any special reason for that decision?” asked Herbert with a
sinking sensation in the region of the heart.
“Well,” yawned the city editor, stretching his arms over his head, “I
don’t know that I should answer that question; but I will say that I
had a talk with Blakeley, the city editor of the Argus, yesterday
afternoon. You can draw your own conclusions.”
Herbert did, and found that the conclusions were not very flattering
to himself. In the course of the next two weeks he visited the local
rooms of nearly every important newspaper in the city; but
everywhere he met with the same experience. In short, he found
himself blacklisted.
In the meantime he made every effort to preserve a cheerful
demeanor. He wrote long letters home to his mother, but never
mentioned the grave disaster which had overwhelmed him and
which threatened to blight his future newspaper life. Fortunately he
possessed a small sum of money which was on deposit in the saving
fund. He had been prudent and thrifty from the time of his arrival in
New York, and as a consequence was able to save small amounts of
money in addition to the allowance which he sent to his mother with
religious regularity. He drew this out now, and counting it over
carefully found that, if necessary, it would be sufficient to pay his
expenses for a month or so. But after all a month, and even two
months pass very rapidly to a poor man who sees no immediate
prospect of earning money. He noted with dismay that a whole week
had been lost in his fruitless negotiations with the Sentinel, and that
a longer period of time had passed by during the time he was
applying to the other newspapers.
At this period he received a letter from Noah Brooks, saying that Mr.
Anderson had told him of the big beat upon which he was working
for the Argus, and wanting to know whether he had been able to
carry it to a successful conclusion. The letter annoyed him, even
coming from such an old and valued friend as the editor of the
Cleverly Banner. However, he sent a courteous reply to his old friend,
expressing regret at his failure to distinguish himself upon that
particular piece of work.
Mr. Anderson, his former teacher, hearing that he had separated
from the service of the Argus, called on him one evening.
“I am awfully sorry to hear this, Herbert, and I half suspect that it is
the result of a quarrel with Blakeley.”
“Yes,” assented Herbert with a half smile, “there is no doubt about
that. Blakeley quarreled all right. I think it was a one-sided quarrel;
but there is no use in discussing it now.”
“But there is use,” insisted the other; “I’ll go to see Blakeley at once
and have this matter straightened out.”
Herbert put a detaining hand on his arm, and said with great
earnestness:
“Please don’t do anything of the kind.”
“But I will,” cried the other.
“But you must not,” corrected Herbert; “if you carry out your good
intentions you will do me a great deal of harm. If you are really a
friend of mine, I beg of you to stay away from the Argus office.”
“But, my young man,” said the teacher, “you are entirely too young
to be so self opinionated. You should not have quarreled with
Blakeley. It would have been much better if you had bent your will to
his.”
Herbert shook his head sadly. He was silent for a few moments, and
then said with much gravity:
“You mean very well, but you cannot mend matters in this instance.”
Mr. Anderson left the house looking very forlorn. He was anxious to
help Herbert, and keenly felt his inability to do so.
Tomlin had been sent out on an assignment that took him to a
remote part of the State. He remained away for a week, and Herbert
was alone during all that period. Tomlin returned unexpectedly one
evening, very anxious to hear the latest news regarding his friend
and the papers. Herbert came in late that night. His white face,
drooping mouth and hopeless eyes told their own story to Tomlin.
However he tried to disguise the feeling that was within him, and
said with assumed cheerfulness:
“Well, old boy, how have you made out in my absence? Have you
tried any of the other papers?”
“Yes,” said Herbert, “I have.”
“Which one?”
“Everyone,” said Herbert with a bitter smile, “at least everyone that
is worth considering.”
“Well, what are your prospects?”
“I have no prospects.”
“No prospects—not even in the future?”
“No,” retorted Herbert, the anger in his heart making him raise his
voice to a high pitch; “not even in the future. To be plain with you,
Tomlin, they all know about the circumstances under which I left the
Argus, and they refuse to have anything to do with me. I am
blacklisted. Do you understand that? I am blacklisted, and a
disgraced man.”
The tone of Herbert’s voice no less than what he said shocked
Tomlin very much; but he made no reply, and the two friends sat
there for many minutes staring mutely at each other.
CHAPTER XVIII
WHEREIN A BLACK SHEEP SHOWS A DESIRE TO CHANGE
HIS COLOR

One morning not long after the conversation which has been
recorded in the previous chapter, Tomlin said to Herbert:
“See here, old chap, you are not going to throw up the sponge—I
know you’re not. You’ve got too much grit and pluck for any such
thing as that.”
“What do you mean?” asked Herbert, staring at him in an
unmeaning way.
“What do I mean? I mean that you’ve got to employ strategy. When
a soldier gets in a tight fix with the enemy, he uses the brains with
which he is endowed for the purpose of extricating himself. So it is
with the lawyer, with the business man and with mortals generally—”
“What in the world are you driving at?” interrupted Herbert.
“I know what I’m driving at,” replied the other. “Listen to what I
have to say, and then try to answer me intelligently. Can you write a
good Sunday newspaper story?”
“Can I? Why you know—”
“Of course, of course I know,” cut in Tomlin, “I only asked you that
question as a matter of form. I want you to go out and get a first-
class special story. Write it up in your most attractive style, typewrite
it on the machine we have in this room, and give it to me by this
time to-morrow.”
The hearty manner of his friend furnished just the sort of inspiration
that Herbert needed at that particular time. He went out during the
day and visited the various places where he would be likely to obtain
material for a special story. It grew quite late and he was still

You might also like