Complete Invent Your Own Computer Games With Python 3rd Edition Al Sweigart PDF For All Chapters
Complete Invent Your Own Computer Games With Python 3rd Edition Al Sweigart PDF For All Chapters
https://ebookgate.com
https://ebookgate.com/product/invent-your-own-
computer-games-with-python-3rd-edition-al-
sweigart/
https://ebookgate.com/product/invent-your-own-computer-games-with-
python-4th-edition-al-sweigart/
ebookgate.com
https://ebookgate.com/product/opencv-computer-vision-with-python-1st-
edition-howse/
ebookgate.com
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
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
https://ebookgate.com/product/computational-physics-problem-solving-
with-python-3rd-edition-paez/
ebookgate.com
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
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.
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
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.
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.
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.
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
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
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
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.
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:
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.
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:
2. Type Python in the search box in the top-right corner of the window.
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
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.
You do not need to type the “9.” on the left side, or the one space immediately following it. Just
type it like this:
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:
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.
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.
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.
When used in this way, +, -, *, and / are called operators. Operators tell Python what to do with
the numbers surrounding them.
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
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
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
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