100% found this document useful (6 votes)
52 views

Instant Access to Coding Club Level 1 Python Basics Roffey C. ebook Full Chapters

Club

Uploaded by

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

Instant Access to Coding Club Level 1 Python Basics Roffey C. ebook Full Chapters

Club

Uploaded by

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

Download the full version of the ebook at

https://ebookultra.com

Coding Club Level 1 Python Basics Roffey C.

https://ebookultra.com/download/coding-club-
level-1-python-basics-roffey-c/

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


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

Coding Club Level 3 Python Building Big Apps Roffey C.

https://ebookultra.com/download/coding-club-level-3-python-building-
big-apps-roffey-c/

ebookultra.com

Passages Level 1 Teacher s Edition Jack C. Richards

https://ebookultra.com/download/passages-level-1-teacher-s-edition-
jack-c-richards/

ebookultra.com

Dead Simple Python Idiomatic Python for the Impatient


Programmer Jason C. Mcdonald

https://ebookultra.com/download/dead-simple-python-idiomatic-python-
for-the-impatient-programmer-jason-c-mcdonald/

ebookultra.com

C Python Tricks And Tips 4th Edition

https://ebookultra.com/download/c-python-tricks-and-tips-4th-edition/

ebookultra.com
Python Create Modify Reuse 1., Auflage Edition Knowlton

https://ebookultra.com/download/python-create-modify-reuse-1-auflage-
edition-knowlton/

ebookultra.com

Aqa a Level Physics Studentbook 1 Aqa a Level Science Nick


England

https://ebookultra.com/download/aqa-a-level-physics-studentbook-1-aqa-
a-level-science-nick-england/

ebookultra.com

Love and Monsters Book Club Boys 1 1st Edition Max Walker

https://ebookultra.com/download/love-and-monsters-book-club-
boys-1-1st-edition-max-walker/

ebookultra.com

Brickwork Level 1 2nd Edition Malcolm Thorpe

https://ebookultra.com/download/brickwork-level-1-2nd-edition-malcolm-
thorpe/

ebookultra.com

Restaurant law basics 1st Edition Stephen C. Barth

https://ebookultra.com/download/restaurant-law-basics-1st-edition-
stephen-c-barth/

ebookultra.com
Coding Club Level 1 Python Basics Roffey C. Digital
Instant Download
Author(s): Roffey C.
ISBN(s): 9781107658554, 1107658551
Edition: Spi ed.
File Details: PDF, 3.44 MB
Year: 2012
Language: english
Codi
Clubng
Python
Basics
cambridge university press
Cambridge, New York, Melbourne, Madrid, Cape Town,
Singapore, São Paulo, Delhi, Mexico City

Cambridge University Press


The Edinburgh Building, Cambridge CB2 8RU, UK

www.cambridge.org
Information on this title: www.cambridge.org/9781107658554

© Cambridge University Press 2012

This publication is in copyright. Subject to statutory exception


and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.

First published 2012

Printed in Poland by Opolgraf

A catalogue record for this publication is available from the British Library

ISBN 978-1-107-65855-4 Paperback

Cambridge University Press has no responsibility for the persistence or


accuracy of URLs for external or third-party internet websites referred to in
this publication, and does not guarantee that any content on such websites is,
or will remain, accurate or appropriate.
Contents
Introduction4

Chapter 1: Python, IDLE and your first program 8

Chapter 2: Some text, some maths and going loopy 16

Chapter 3: Readable code and the MyMagic8Ball game 28

Chapter 4: Functions 45

Chapter 5: MyEtchASketch 55

Taking things further 73

Appendix74

Glossary and Index 77

The Quick Quiz answers 81

Acknowledgements82

Contents 3
Introduction
Why was this book written?
This book is the first in a series of books for anyone with little or no knowledge of computer
programming but who would like to give it a go.

Who is this book for?


One factor was the availability of a computer that any child could save up for or get for their
birthday, such as the Raspberry Pi from www.raspberrypi.org.

But my wish to produce a series of short books on coding goes back much further than that.
When I grew up, computers were very different from the PCs we use today. To play a game or
use a word-processor, you had to run the program by typing green text into an empty black
screen. But the great thing was, you could also type in your own commands and run them! It
was not long before I had written my first text-based game in a language called BASIC.

Introduction 4
Later on, I wanted to learn a more modern language, and set about teaching myself Java. I
read four or five books and completed the examples, but at the end of each one I was left in
a dreadful situation: I had all sorts of ideas for programs I wished to make, but still no idea
how to start! I could make the exciting projects that were the focus of these books, but not
much else. So with this series of books, I have taken a different approach. I hope it will teach
you the skills you need to write any program you can imagine – eventually – and many
simple programs straight away.

Why should you choose this book?


After many years of looking, I finally found a great book on Java called Introducing Java by
David Parsons, published by Thomas Learning. It was for university students. Suddenly I
understood why we did certain things and how to start designing complex programs. If only
I had started with this book to begin with!

I want you, the reader, to learn not only how to make the programs in this book but also how
to design your own. I want you to be able to write programs well, so that if you take it further
and become the inventor of the next Google you will not have to unlearn bad programming
habits. Unlearning things, I should add, is a lot more difficult than you might imagine.

What needs to be installed?


You do not have to do this! Please ask a responsible adult to read the Introduction for Adults
page on the coding club website (www.codingclub.co.uk) so that they can get everything
organised for you. If you are able to do this by yourself then full instructions can be found at
http://python.org/download/. If you are going to learn to program on a Raspberry Pi, it will
be very easy to get things ready as it comes pre-installed with everything you need. You do
not have to use a Raspberry Pi to run Python. You can use Windows, Apple Mac and
Linux systems. Introduction 5
How to use this book
It is hoped that you will read this book carefully and build all the main projects in order.
At the end of each chapter there are further ideas, and challenges that you can think of as
‘mini quests’ in a video game. Some readers will want to work through all of them so that
they understand everything all the time. Some of you will probably prefer to rush through
and get to the end. When these readers think: ‘What can I do now?’ One answer is to go back
and look at some of the ideas at the end of each chapter. Which approach is best? The one
you are most comfortable with. If you are being guided by a teacher though, then to enable
them to help you the most you should trust their judgement.

There are four ways in which this book tries to help you to learn:

1 By copying the code – this is important as it gets you to work through the code a line at a
time (like computers do) and will help you remember the details in the future.
2 Finding and fixing errors – error messages in Python give you some clues as to what has
gone wrong. Solving these problems yourself will help you to be a better programmer.
In the end though, this should not become boring, so if you get stuck the code can be
downloaded from the accompanying website.
3 Experimenting – feel free to experiment with the code we write. See what else you can
make it do. If you try all the challenges, puzzles and ideas, and generally mess with the
code, this will help you learn how to write code like a professional.
4 Finally, this book will not only provide the code to build some cool, short projects but
also teach you how the programs were designed. You can then use the same methods to
design your own applications.

Introduction 6
A word of warning
You may be tempted to simply get the code off the web site instead of typing it yourself. If
you do this you will probably find that you cannot remember how to write code so easily
later. You will only be asked to type small chunks of code at a time – remember that this will
help you understand every detail of your programs.

You will also become a faster typist, which is a very important skill these days!

Introduction 7
Chapter 1
Python, IDLE and your first program

In this chapter you are going to:

• learn about computer programming and the different languages that you can use

• meet the Python programming language

• learn how to use IDLE, which will help organise your programs and allow you to run
them easily

• check that your computer has been set up correctly

• write and run your first program.

Chapter 1: Python, IDLE and your first program 8


Coding
Coding is writing instructions for a computer to perform a task. This code has to be in a form
that the computer can understand. This is more formally known as computer programming.

Computers and coding have not been around for a long time but they have sure packed in
some interesting history in a short space of time. The first machine that stored instructions
in a way that future computers could take advantage of was the Jacquard loom that used
holes punched in cards and was invented in 1801. Charles Babbage is often credited with
inventing the first computer which he described in 1837 but was not built until 100 years
later. In 1989 Guido van Rossum started to create the Python programming language which
he named after Monty Python’s Flying Circus, a BBC comedy sketch show.

Programming languages
There are many programming languages currently used by coders around the world. Some
are best in one situation, others in another.

• HTML is good for producing web pages.

• SQL is great at making databases do what you want.

• P
 ython is brilliant for writing quick applications, running programming experiments
and for building larger applications, including games.

Chapter 1: Python, IDLE and your first program 9


If you have previously programmed in Scratch (produced by MIT) you will find you can
pick up Python very quickly. Scratch is great for learning how to think like a programmer
and is very good for making games. If you have not tried Scratch before, you might
enjoy trying that next because the ability to learn a new programming language is an
important skill for coders. You will find it is a lot easier than learning a new human
language.

Once you have learned one modern programming language, you can quickly learn others.
You simply have to find out how your new language handles variables, loops, etc. (You will
know what these are by the end of the book.)

Python
Python is a typed computer language. This makes writing short programs very fast and you
can produce almost anything you can imagine.

Python is a powerful, modern programming language used by many famous organisations


such as YouTube and NASA. It is one of three programming languages that can be used to
write Google Apps. Python is a great language. Enjoy!

IDLE
You will start programming in IDLE which comes with Python. IDLE is a special text editor
like Microsoft Word, except it understands Python and helps you get your code right. IDLE is
itself, a Python application.

Chapter 1: Python, IDLE and your first program 10


Let’s look at IDLE:

Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53)


[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>

IDLE when started on an Apple Mac.

The code you want to run is typed after the special entry prompt:

>>> my code goes here

To run the code we press the return key. This is how Python runs in IDLE’s interactive mode.
Python can run files as well but to start with, this is all we need.

Let’s see how IDLE looks on a Windows PC:

Python 3.2.1 (default, Jul 10 2011, 20:02:51)


[MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>

IDLE when started on Windows 7.

Chapter 1: Python, IDLE and your first program 11


And finally, how IDLE looks on a Linux computer:

Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)


[GCC 4.4.5] on linux2
Type "copyright", "credits" or "license()" for more information.
>>>

IDLE when started up on the Raspberry Pi computer.

A great reason for learning Python and using IDLE as our IDE (Integrated Development
Environment) is that it is very similar on all the different types of computers available.

The text before the >>> prompt is unimportant at the moment. However, it is always useful
to know what version of Python you are using.

Hello World!
Since the dawn of programming, when the first cave-coders booted up their cave-computers,
it has been a tradition that your first program when learning a new language is ‘Hello
World’. The aim is to try to make the computer say ‘hello’ to the world. If you can do this
you will have tested whether everything that was set up for you is working properly.

Chapter 1: Python, IDLE and your first program 12


• If it is not already started, start up IDLE.

• After the >>> prompt write in the code from Code Box 1.1 and then press your return
key to run the program.

Code Box 1.1


print("Hello World!")

If all is well, you should get something like this:

Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)


[GCC 4.4.5] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> print("Hello World!")
Hello World!
>>>

Hello World!

Python has followed your instruction and output ‘Hello World!’

You have written your first computer program. Well done!

Chapter 1: Python, IDLE and your first program 13


Making mistakes
Did you get a syntax error?
Syntax errors are very common when typing in code (as are other errors). If you make one
or two it is not your fault. It is because although computers are fast, they can also be a bit
stupid. If there are any tiny mistakes in your code, they panic and produce error messages.
These messages try to explain to you what the problem is but they are often difficult to
understand.

Colons, brackets, speech marks, apostrophes and spelling of Python words have to be just right.
Although we can read imperfect sentences, computers cannot.

Whether or not you got any errors, try this Quick Quiz.

Quick Quiz 1
Which of these lines of code are correct?
1 Print("Hello world!")
2 print("Hello world!")
3 print(Hello world!)
4 print "Hello world!"

Notice how the coloured text helps you spot code that is not going to work. All the code
listings in this book use the same coloured text as in IDLE’s standard display. This should
help you to spot bugs in your code.

Chapter 1: Python, IDLE and your first program 14


Chapter summary
In this chapter you have learned:

• that programming is writing instructions for computers


• that there are many different computer languages
• why Python is a great language to learn
• how to use IDLE in interactive mode
• how to write and run a simple program
• that the print() command means ‘show on the screen’ not ‘send to the printer’.

Idea 1
1 Write some new code so that a short message is displayed that says thank you to
whoever got everything ready for you.
2 Run your new code to display the message.
3 Now show them your message. This will make them happy.

Idea 2
1 Write some code so that the computer will show the text for a joke.
>>> print("Question: What goes clip?")
Question: What goes clip?
>>> print("Answer: A one legged horse")
Answer: A one legged horse
>>>
Chapter 1: Python, IDLE and your first program 15
Chapter 2
Some text, some maths and going loopy

In this chapter you are going to:

• learn how to do some more with text

• get Python to do some maths for you

• learn about how while loops work

• learn lots of useful operators.

This is a fun chapter as we get to start some real programming!

Chapter 2: Some text, some maths and going loopy 16


Text
Escape sequences
Try opening IDLE in interactive mode and enter the code in Code Box 2.1.

Code Box 2.1


print("Question: What goes clip?\nAnswer: A one legged horse.")

If you have not pressed your return key yet, to see what happens, do so now.

You should have discovered \n has a special purpose. It is an example of an escape


sequence. Table 2.1 shows some more escape sequences.

Escape sequence What it does


\n creates a line return in a string of text
\t creates a tab style indent in a string of text
\\ allows a backslash to appear in a string of text

\" allows a speech mark to be used in a string of text

Table 2.1 Escape sequences.

Chapter 2: Some text, some maths and going loopy 17


Experiment
Try writing a variety of little programs in IDLE using the escape sequences
in Table 2.1 until you feel you know what they all do.

Backslashes
Are you a bit confused about the last two escape sequences? If so, type in and run the code
from Code Box 2.2.

Code Box 2.2


print("Here is a speech mark: \" and here is a slash: \\")

Try typing in the code from Code Box 2.3 to see how to avoid having to escape speech marks.
This takes advantage of the fact that you can choose whether to surround strings in double
speech marks or single ones. Watch out though, you will get a lot of syntax errors if you do
not do this carefully.

Code Box 2.3


print('I say "High", you say "Low". You say "Why?" and I say "I don\'t know". Oh no.')

Chapter 2: Some text, some maths and going loopy 18


The backslash is used to ‘escape’ characters that are used in Python. When we want to print some
text to the screen we wrap it in speech marks. This now means that there is a problem if you want
to type some speech marks. Well, you know what to do about it – put a backslash before it. So
what do you do if you want to actually print a backslash to the screen? Put a backslash before it!

Functions
print()is called a function (these are covered in chapter 4, page 53). What print()
will do, is print anything you throw at it inside the brackets. They must be separated by
a comma, and strings (bits of text) must be put in speech marks. Everything inside the
brackets will be printed out in order. The results from sums can also be output, but you must
not put the calculations in speech marks. What do you think would happen if you left in the
speech marks? Don’t forget you can also add in escape sequences.

Maths
Using Python as a calculator is easy, if you remember two things:

1 In Python, as in almost all programming languages, the multiplication symbol is an


asterisk.
2 The division symbol is a forward slash.
>>> 10/4
2.5
>>> 3*3
9
>>>
Chapter 2: Some text, some maths and going loopy 19
There is another way of dividing. If you use two forward slashes instead of one, Python will
produce an integer as an answer. An integer is a whole number (a decimal such as 2.5 is
called a float). You can now find the remainder, with another mathematical operator
called the modulus. This is represented by a % sign.

>>> 11/4
2.75
>>> 11//4
2
>>> 11%4
3
>>>
0

Table 2.2 lists some more mathematical operators.

Operator Name Example Answer


* multiply 2*3 6
/ divide (normal) 20/8 2.5
// divide (integer) 20//8 2
% modulus 20%8 4
+ add 2+3 5
- subtract 7-3 4

Table 2.2 Maths operators.

Chapter 2: Some text, some maths and going loopy 20


Experiment
In interactive mode, check that the examples in Table 2.2 do give the
correct answers and then try out some of your own favourite sums. You
might like to see what happens if you wrap a maths sum inside speech
marks in the print() function.

Combining text and maths


It is also possible to combine text (or strings) and numbers in the print() function. The
comma is used here as a separator between the text and the maths.

>>> print("111 divided by 4 = ", 111/4)


111 divided by 4 = 27.75
>>>
>>> print("11 divided by 4 = ", 11/4)
11 divided by 4 = 2.75
>>>

Quick Quiz 2
Can you work out what the output from this code will be?
>>> print("11 divided by 4 also equals: ", 11//4, " remainder: ", 11%4)

Chapter 2: Some text, some maths and going loopy 21


Going loopy
Computers are great at repetitive tasks. So are humans, but we get bored easily! Computers
are not only good at them, they are fast! Therefore we need to know how to tell them to do
repeats. To do this we use a while loop. This runs some code while something is true and
stops when it becomes false.

Imagine you were trying to write some code in a History lesson at school, when you should
be doing History. Your teacher might ask you to write fifty lines. Well no matter, Python can
do that.

Try opening IDLE in interactive mode and then enter the code in Code Box 2.4. You will need
to press return twice at the end.

Code Box 2.4


>>> lines=0
>>> while lines < 50:
print("I will not write code in history lessons.")

lines = lines+1

Here is another solution to the same problem:

Code Box 2.5


>>> print("I will not write code in history lessons.\n" *50)

Chapter 2: Some text, some maths and going loopy 22


The code in Code Box 2.5 is clever – look carefully to see what is happening. Run it if you are
not sure. Although the code in Code Box 2.4 is longer, a while loop is often more useful as it
can do far more complex tasks. For example, with a while loop you can ask a computer to
count to 100. Try entering the code from Code Box 2.6 and running it.

Code Box 2.6


>>> number=1
>>> while number < 101:
print(number)
number = number+1

How do while loops work?


Variables

To start with we create a variable and assign a value to it. A variable is a space in the
computer’s memory where we can store, for example, a string or an integer. We create a
variable by naming it. In Code Box 2.6 we called our variable ‘number’ and with the equals
operator we give it the value ‘1’.

The next line of code >>> while number<101: says ‘while the variable called number is less
than 101 do the following’. All of the code that is indented after the colon is to be repeatedly
performed by the computer. That is, it loops through these two lines of code until number is
no longer less than 101.

Chapter 2: Some text, some maths and going loopy 23


create a variable and assign it the value 1

number=1 the colon says to run all of the indented code


while number < 1: there are no speech marks here as we want the value
print(number) of number not the word “number”
number = number+1
the variable number is incremented by 1
IDLE automatically indents for you!

The last line of code number = number+1 is in the loop. It keeps adding 1 to number for
number = 1
each passage through the loop. Don’t forget the variable’s value can be changed with the
equals operator at any time. number 1,

Delving Deeper
The equals sign is used differently to the way it is used in maths. In computing, the equals sign means ‘point
this variable name at this piece of data’ (an integer for example). So number=1 means ‘create a variable
called number and point it at the integer 1’. Another way of saying this is ‘assign the value 1 to the variable
number‘. Later we may assign another value to number.

Chapter 2: Some text, some maths and going loopy 24


Operators

There are several operators you can use in a while loop. Some examples are given in Table
2.3. Note how we now have another version of equals ==. This form is more like the equals
in maths. It is an example of a comparative operator. Therefore, while number==1:
means ‘while the variable called number is equal to 1, do the following’.

Operator Meaning
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
Table 2.3 Comparative operators.

We use a double equals sign to compare two values and a single equals sign to assign a
value to a variable.

Chapter 2: Some text, some maths and going loopy 25


Chapter summary
In this chapter you have learned:

• how the print() function is very flexible


• how to write and run simple maths code
• how to output a mixture of strings, maths or numbers
• how to write a while loop and use comparative operators

Puzzle 1
Write some code in IDLE so that the computer counts up to 20 in twos.

Puzzle 2
Write some code so that the computer outputs the 5 times table like this.

1x5=5
2x5=10
3x5=15

Hint: You will need a counter variable which you could call number. Then
you should find out how to write one line, and then make your loop do it 10
times.

Chapter 2: Some text, some maths and going loopy 26


Puzzle 3
See if you can re-write the following code in three different ways so that each
program still produces output which counts to a hundred.

>>> number=1
>>> while number < 101:
print(number)
number = number+1

In your new code, you are not allowed to use the less than operator <.
Instead you should use one of these comparative operators in each program:
<= > !=

Answers to all of these puzzles can be found on the companion website


www.codingclub.co.uk.

Chapter 2: Some text, some maths and going loopy 27


Chapter 3
Readable code and the MyMagic8Ball game
In this chapter you are going to:

• write and save a Python file using script mode

• learn how to write clear readable code

• run a Python file

• learn about how to get user input

• learn about if and else

• write a short game called MyMagic8Ball.

You are going to build and save a Magic 8 Ball game. If you have not played with one of
these toys before, what you do is, ask the 8 Ball for some advice, shake it and it magically
responds.

Chapter 3: Readable code and the MyMagic8Ball game 28


Script Mode
Open IDLE in interactive mode and then from the File menu choose New Window. A new
window appears that is apparently blank. When you type in this window and save the file you
are working in script mode. The file name must end in .py to show that it is Python code.

Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) # MyMagic8Ball


[GCC 4.4.5] on linux2
Type “copyright”, “credits” or “license()” for more information. import random
>>>
# write answers
ans1=”Go for it!”
ans2=”No way, Jose!”
ans3=”I’m not sure. Ask me again.”
ans4=”Fear of the unknown is what imprisons us.”
ans5=”It would be madness to do that!”
ans6=”Only you can save mankind!”
ans7=”Makes no difference to me, do or don’t - whatever.”
ans8=”Yes, I think on balance that is the right choice.”

print(“Welcome to MyMagic8Ball.”)

# get the users question


question = input(“Ask me for advice then press ENTER to shake me.\n”)

print(“shaking ...\n” * 4)

IDLE – interactive and script modes side by side.

Try typing the code from Code Box 3.1 into your new script mode window. These are the first
lines of the MyMagic8Ball game.

(If you have a British Apple keyboard, you will need to hold alt and click the £ symbol to type #.)
Chapter 3: Readable code and the MyMagic8Ball game 29
Code Box 3.1
# MyMagic8Ball
import random
# write answers
ans1="Go for it!"
ans2="No way, Jose!"
ans3="I’m not sure. Ask me again."
ans4="Fear of the unknown is what imprisons us."
ans5="It would be madness to do that!"
ans6="Only you can save mankind!"
ans7="Makes no difference to me, do or don’t - whatever."
ans8="Yes, I think on balance that is the right choice."

Now you should save your work by choosing Save from the File menu. It is a good idea
to save all your code into a special folder which you can call – ‘Python Code’ – in your
documents folder. Call the new file myMagic8Ball.py.

Analysis of Code Box 3.1


The # symbol

The # symbol says to the computer, ‘ignore the rest of the text on this line, it is for
humans’. This is called commenting. You have typed in two comments so far.

Chapter 3: Readable code and the MyMagic8Ball game 30


Modules
import random uses a new Python word – import – followed by the name of a Python module.

A module is a Python file with special code that you do not have to write yourself but that
you can use. There are many modules available and it is also possible to write your own. So
import random brings in to your application a selection of functions that you can use later
in your program. (Chapter 4 is all about functions.)

String variables

The last 8 lines of code are the variables where you store some strings (bits of
text) that will be used later in the game. At this early stage you may be asking Delving deeper
yourself, how do I know what to call my variables? Well within reason you can
call them what you like. There are only 31 reserved words in Python. There are 31 Python words that you cannot
use as your own variable names. These are:
and as assert break class continue

Writing tidy code def del elif else except finally


for from global if import in is
lambda nonlocal not or pass print
It is important to write your code so that it is easy for you to read it later, when raise return try while with yield
you have forgotten how you did things. It also makes it easier, if your code is You must also be very careful to use only
well written, for other coders to understand what you did. letters and underscores and no unusual
characters such as & ! @ $ * ( ) ? : ; [ ] “
White space < > ‘ ` | = { } \ /. Spaces are not allowed
either. Numbers are allowed but not at the
beginning of your variable names.
Lots of computer languages like Java, PHP and C++ wrap chunks of code in
curly brackets. Each statement has to end in a semicolon.

Chapter 3: Readable code and the MyMagic8Ball game 31


{
private int current_floor = 0;
public int getFloor()
{
return current_floor;
}
public void moveToFloor(int floor_number)
{
current_floor = floor_number;
}
}
Java code.

Python does not require semicolons or curly brackets. Semicolons can be very annoying as
they are easy to forget and if you do forget one, your program will not run at all.

In Python, each line of code simply requires that you have a line ending. This is a lot easier
to spot if you do manage to forget!

To group lines of code together you indent the code (four taps on the space bar). However
IDLE will usually know when you should indent and do it for you when you press return!
This indenting produces ‘white space’. The code is grouped according to how you arrange the
white space. This is how the same code would look in Python.
class Lift():
current_floor=0

def getFloor():
return current_floor

def moveToFloor(floor_number):
current_floor = floor_number
Python code. Chapter 3: Readable code and the MyMagic8Ball game 32
Delving deeper
There are other differences to note. Java has a lot of extra words like public, private, int and void. This is
because it is a very strict language where everything has to be carefully defined. Python instead, will usually
work out whether something is an integer (number) or string (text) for the programmer. Both languages have
their advantages and disadvantages.
Classes are not dealt with in this book but we do have to use some for our final project in chapter 5. You will
learn about the def keyword in the next chapter!

More about commenting


Don’t be surprised if you had no idea what any of the code above meant. Even if you had
already read this book, it can be difficult to read other people’s code. Remember, it is written
for computers to understand, not us. Remember, we can leave little notes or comments as we
go using the hash symbol #.

Here is the same Python code as above with some comments.

# This is a class that describes a lift (or elevator in the USA)


class Lift():
# The lift starts on floor zero
current_floor=0
# The method for finding the lift
def getFloor():
return current_floor
# The method for moving the lift
def moveToFloor(floor_number):
current_floor = floor_number

Python code with too many comments. Chapter 3: Readable code and the MyMagic8Ball game 33
As you can see, it is possible to add too much commenting! Sometimes simply naming things
well is much better. The names chosen by the programmer here include Lift,
current_floor, getFloor, moveToFloor and floor_number. The only Python code words
are class and def.

Naming variables
If you want to store a number or some text somewhere you do so in a variable.

Variables should always be named with descriptive names. You should always start with a
little letter. You can separate words with underscores like this my_own_variable.

Getting user input


Getting user input is surprisingly simple in Python. We use another supplied function
input(). This function is very similar to the print() function in as much as it can be given
a string which it sends to the screen. The difference is it can only take one string and it then
waits for the return key on the keyboard to be pressed. This means that it can be used to
pause a program or wait until the user is ready. However it does one other thing: it returns,
as a string, everything that is typed by the user until the return key is pressed. This can be
collected in a string variable like this.

keyboard_input = input("Enter some text please.")

Chapter 3: Readable code and the MyMagic8Ball game 34


Experiment
• I n interactive mode, try typing the code in Code Box 3.2 to see how this works. When
the computer asks for your name, tell it who you are, press return and then complete
the code.

Code Box 3.2


>>> name = input("What is your name?\n")
>>> print("Hello ", name)

• Try and see what you can do with input() without supplying any text.

• By combining print() with input() you can make up for input’s inability to handle
complicated combinations of strings and maths. See if you can work out how. (Hint:
Just use input() on its own, after a complicated print() function.)

Now back to script mode.

After your eight variables in myMagic8Ball.py, miss a line and type in the code from Code
Box 3.3.

Code Box 3.3


print("Welcome to MyMagic8Ball.")
# get the users question
question = input("Ask me for advice then press RETURN to shake me.\n")
print("shaking ...\n" * 4)
Chapter 3: Readable code and the MyMagic8Ball game 35
The variable question is given the value from the result of the input() function. That is,
it now stores whatever was typed by the person playing the game before they pressed return.
In this version you will not use this variable. In fact the player might as well speak. However,
you may want to customise the game later so it is good design to store this input somewhere
obvious, just in case. You will find that you understand the rest of this code now. If you are
not sure what the last line in Code Box 3.3 does, you could copy that into the interactive
mode window and find out.

Using the random module


The first line of code in Code Box 3.1 imports Python’s random module. This gives your
program access to a number of functions. You will use just one – randint(). This function
takes two integer arguments. Arguments are the values that you provide for a function to do
its task. You will learn more about this in chapter 4.

A simple dice
To create a dice requires only one line of code in interactive mode.

>>> random.randint(1, 6)

We have to put random. before randint() to tell the computer that this function can be
found in the random module. The two arguments are the start number and the end number.
The function randomly chooses 1, 2, 3, 4, 5 or 6. Try it out a few times in interactive mode to
see it in action.

Chapter 3: Readable code and the MyMagic8Ball game 36


Back in script mode
Back in the myMagic8Ball.py window type the code from Code Box 3.4. You will see that
we use the randint() function to generate a random number between 1 and 8 and assign
the result to a variable called choice.

(Hint: You can save yourself a lot of typing by copying and pasting. Remember that
whenever you do this, it means there is probably a better way of writing your code!)

Code Box 3.4


# use the randint() function to select the correct answer
choice=random.randint(1, 8)
if choice == 1:
answer=ans1
elif choice == 2:
answer=ans2
elif choice == 3:
answer=ans3
A random image!
elif choice == 4:
answer=ans4
elif choice == 5:
answer=ans5
elif choice == 6:
answer=ans6
elif choice == 7:
answer=ans7

(continues on the next page)


Chapter 3: Readable code and the MyMagic8Ball game 37
else:
answer=ans8
# print the answer to the screen
print(answer)
input("\n\nPress the RETURN key to finish.")

Analysis of Code Box 3.4

if, elif and else


The last part of the code in Code Box 3.4 used the Python words if, elif and else. They are
very easy to understand when you realise that elif is short for else if. Look at this bit of code.

if 
choice == 1:
answer = ans1

The first line says, ‘if the value of choice is equal to 1, then run the code that is indented
after the colon.’

Notice how the comparison operator == is used, in the same way as it was with the while
loop in chapter 2.

Chapter 3: Readable code and the MyMagic8Ball game 38


So, if choice does equal 1 the program creates a new variable and calls it answer. Using the
equals sign it is given the string that is held by your variable ans1 which you typed at the
beginning of the program. So now answer would hold the string "Go for it!".

The random generator randint(1, 8) may not have produced the value 1 though, so
if
the next bit of the code handles the situation if choice equals 2:.
if
elif choice == 2: else elif
answer=ans2 else

So in this case answer would hold the string, "No way, Jose!".

This continues until the application handles all other situations with else:.
In your program this means if the choice is 8.

else:
answer=ans8

Two uses of input

The input() function is used twice in this program. The first time, it takes the
user input and stores it in a variable called question.

Chapter 3: Readable code and the MyMagic8Ball game 39


question = input(
"Ask me for advice then press ENTER to shake me.\n")

Do you remember how the user’s input is not actually required? What this line of code does
do, is wait until the return key is pressed and stores the input just in case we decide to use it
some other time.

At the end of the program we use the input() function again.

input("\n\nPress the RETURN key to finish.")

This line does not even bother storing the user input at all. It just supplies two line returns
and a message to say the game is over. The program again waits for the user to press the
return key and then finishes.

This is much better than suddenly finishing the game unexpectedly and you will see it used
a lot from now on.

You have entered all the code for this program now. If you have not saved it, do so now and
then check it against the complete listing in Code Box 3.5.

Chapter 3: Readable code and the MyMagic8Ball game 40


Putting it all together
Here is the complete code as seen in IDLE.

Code Box 3.5


# MyMagic8Ball
import random
# write answers
ans1="Go for it!"
ans2="No way, Jose!"
ans3="I’m not sure. Ask me again."
ans4="Fear of the unknown is what imprisons us."
ans5="It would be madness to do that!"
ans6="Only you can save mankind!"
ans7="Makes no difference to me, do or don’t - whatever."
ans8="Yes, I think on balance that is the right choice."
print("Welcome to MyMagic8Ball.")
# get the users question
question = input("Ask me for advice then press ENTER to shake me.\n")
print("shaking ...\n" * 4)
# use the randint() function to select the correct answer
choice=random.randint(1, 8)
if choice==1:
answer=ans1
(continues on the next page)
Chapter 3: Readable code and the MyMagic8Ball game 41
elif choice==2:
answer=ans2
elif choice==3:
answer=ans3
elif choice==4:
answer=ans4
elif choice==5:
answer=ans5
elif choice==6:
answer=ans6
elif choice==7:
answer=ans7
else:
answer=ans8
# print the answer to the screen
print(answer)
input("\n\nPress the RETURN key to finish.")

Running programs in script mode


To run the code you must first remember to save it with the .py at the end. Now with the
finished myMagic8Ball.py file open, choose Run Module from the Run menu. The program
will run in the interactive mode window. Try it out.

Chapter 3: Readable code and the MyMagic8Ball game 42


Chapter summary
In this chapter you have learned:

• how to write and save a Python file using script mode


• how to write clear readable code with comments and descriptive variable names
• how to run a Python file
• how to get user input
• about if, elif and else
• how to write a short game called MyMagic8Ball.

You have worked hard and learned a lot in this chapter. It is time you experimented a bit!

Idea 1
 ry out the game on some friends or relatives. (Hint: Make sure they cannot see the
T
code, as this will ruin the game.)

Idea 2
Change the eight string variables to answers you want your Magic8Ball to say.

Chapter 3: Readable code and the MyMagic8Ball game 43


Exploring the Variety of Random
Documents with Different Content
settled in Newport when he was 24 years of age, married there in
1779, and had 14 children. At the close of the Revolution, Mr. and
Mrs. Goldsmith removed from Newport.
James Calhoun, grandfather of John C. Calhoun, came from
Donegal, Ireland, in 1733, with his family, and settled in
Pennsylvania, later removing to western Virginia, and at a later
period, further south. In 1765 they established the “Calhoun
settlement” in South Carolina, near the Cherokee Indian frontier.
James Blaine came from Ireland with his family prior to 1745. He
settled in Toboyne township, Cumberland County, Pa., where he died
in 1792. He left a widow and nine children. Col. Ephraim Blaine of
the Revolution was one of these children. The late Hon. James G.
Blaine of Maine was a descendant.
One of the officers in the Irish-French regiment of Dillon, during
the American Revolution, was Patrick Murphy. His name is
preserved in the military archives of France, and by its publication in
Les Combattants Francais De La Guerre Americaine, is recalled and
forever made known to the American people.
Mary Peisley was a native of Kildare, Ireland, and was born in
1717. She entered the Quaker ministry about 1744, came to America
with Ann Payton, and perhaps other Quakers, about 1753, labored in
New York, the Carolinas, Maryland and Rhode Island; returned to
Ireland and married Samuel Neale of Dublin.
James Moore, who was chosen governor of South Carolina, was
born in Ireland about 1640. He came to this country in 1655, settled
in Charleston, S. C., wedded a daughter of Sir John Yeamans and had
10 children. One of his sons, also named James Moore, was likewise
chosen governor of South Carolina.
Born in Ireland in 1705, Jeremiah Smith came to Boston, Mass.,
with his wife, in 1726, and finally settled in Milton, Mass., 1737. He
was an intimate friend of Governor Hutchinson, Governor Hancock
and other leading men. He engaged in the manufacture of paper, and
carried on the business until 1775 when he retired.
The Virginia records show that Symon Tuchin was in that colony
in 1625. He was master of the Due Return, and “having been
banished out of Ireland was reported as strongly affected to popery.”
Accordingly, “The Governor and Council of Virginia sent him as a
prisoner, in January, 1625, to the Company in England.”
Mary Mallins, “from Bandon in Ireland,” was among those
arrested in Boston, Mass., at the time of the prosecution of the
Quakers, she being one of the latter. She and twenty-seven other
Quakers were finally liberated by Endicott and were ordered to leave
the jurisdiction at once, nor to return at their peril.
Morison’s Life of Judge Jeremiah Smith, who was a native of
Peterborough, N. H., states that “He began to study Latin when
about twelve years old, with Rudolphus Greene, an Irishman
employed by the town to keep school a quarter of the year in each of
the four quarters of the town.” Judge Smith was born about 1771.
John Mitchell, a native of Ireland, was muster-master-general of
the Pennsylvania State navy, 1775–’76; acting commissary, 1776–’77;
lieutenant on the Chatham, 1775; captain of the Ranger, 1776; a
merchant in France after the Revolution; United States consul at
Santiago de Cuba; admiralty surveyor of Philadelphia, Pa.
A Rhode Island soldier, 1756–’59, was named William Sheehan.
He is mentioned in the former year as a lieutenant and
quartermaster for the expedition against Crown Point. In 1758, he
appears as first lieutenant in the major’s company of his regiment,
and is also referred to the same year as captain and quartermaster.
A Virginia trooper who rendered service against the French and
Indians was Thomas Doyle. The Assembly of Virginia passed an act
in 1756 for the payment of men engaged in said service. Doyle was
voted 1,860 pounds of tobacco, and other troopers were to be paid
like amounts. (Boogher’s Gleanings of Virginia History.)
Daniel Magennis is a name frequently met in King Philip’s War,
1675–’76. Daniel became a corporal and was at one time company
clerk. He served at various times under Captain Henchman, Captain
Wheeler and other commanders. His name also appears in the
records as Maginnis. (See Bodge’s History of King Philip’s War.)
Col. Charles Stewart was born in County Donegal, Ireland, 1729.
He came to America, 1750; was deputy surveyor-general of
Pennsylvania; patriot of the Revolution; colonel of a New Jersey
regiment of Minute Men; colonel of a New Jersey regiment of the
Line; served on Washington’s staff; member of the Continental
Congress.
“In the Mayflower ... were one hundred and one men, women,
boys and girls as passengers, besides captain and crew. These were of
English, Dutch, French and Irish ancestry, and thus typical of our
national stock.” (Rev. William Elliot Griffis in Brave Little Holland
and What She Taught Us. New York, 1894. Page 208.)
Bernard O’Neill was a captain in the Irish-French regiment of
Dillon in the American Revolution. He was probably the “Captain
Commandant O’Neill” who participated in the expedition against
Savannah, where he was wounded in the breast, and may have been
identical with “Le Baron Bernard O’Neill,” who became a Chevalier
of St. Louis.
Thomas DeCourcy was a native of Newport, R. I. His father came
from Ireland and settled in Newport about 1720. The father’s
brother, also named Thomas, was Baron Kinsale. Upon the latter’s
death, Thomas, the native of Newport, succeeded to the title and
estates. Mention of these facts may be found in Peterson’s History of
Rhode Island.
Eleanor Ledlie was of Irish parentage. She became the wife of
Capt. Samuel Bowman, an officer of the Revolution, who as
commander of the guard walked arm in arm with Major Andre, the
British spy, to the place of the latter’s execution. (Hon. Edward A.
Moseley of Washington, D. C., in an address to the American-Irish
Historical Society.)
Matthias Alexis de Roche Fermoy, of Irish extraction, was an
officer in the French forces that came to America during our
Revolution and assisted in establishing the independence of the
United States. He became a brigadier and is mentioned in the work
entitled Generals of the Continental Line in the Revolutionary War
(Philadelphia, 1903).
Brian Murphy was a soldier in King Philip’s War, 1675–’76. He is
mentioned in Bodge’s history of that war and is credited with
garrison duty at Mendon, Mass. Thomas Tally, Patrick Morren,
Timothy Larkin, Joseph Griffin, Jeremiah Toy, Philip Butler, John
Hand and Thomas Welch are also mentioned by Bodge as
participating in that struggle.
During the Revolution, Capt. William Burke of the armed schooner
Warren was captured by the British frigate Liverpool and carried
into Halifax, from whence he was sent to New York and confined on
board a prison ship. He was later exchanged for Capt. Richard Jones,
“a British officer of equal rank.” Captain Burke is mentioned as of
Marblehead, Mass.
Susannah Lightfoot, a native of Ireland, was born in 1720. She was
a Quaker, and with Ruth Courtney came from Ireland to America on
a visit to Friends here. On her return to the Old Land, she landed at
Cork. In 1760, she paid a second visit to these shores, and four years
later removed with her husband from Ireland and permanently
settled here.
Among those serving under Esek Hopkins, during the Revolution,
was Patrick Kaine. He is mentioned as a marine and served aboard
the Cabot. In an engagement with the British ship Glasgow, April 6,
1776, he was killed. Anthony Dwyer, Richard Sweeney, John Connor,
Thomas Dowd and Andrew Magee also served aboard the Cabot
under Hopkins.
Jeremiah Driskel, William Henussey and John Leary all served in
the Commander-in-Chief’s Guard (Washington’s) during the
Revolution. Driskel had previously served in a Maryland regiment;
Henussey, in a Pennsylvania command, and Leary, in a regiment
commanded by John Stark. (See Godfrey’s work on The
Commander-in-Chief’s Guard.)
In 1776, John O’Kelley was a member of a military company in the
town of Warren, R. I. The company was commanded by Capt. Ezra
Ormsbee. Also in the company were Daniel Kelley and Joseph Kelley.
The General Assembly of Rhode Island, in 1782, gave “Mrs. Elizabeth
O’Kelley, widow of John O’Kelley,” of Warren, permission to sell
certain real estate.
Thomas Jones, “from Strabane, Ireland,” came to Rhode Island
prior to 1699; later he removed to Long Island, N. Y. He married
Freelove Townsend, whose father gave them land at Massapequa,
where they settled. They are mentioned in Bunker’s Long Island
Genealogies. Mr. and Mrs. Jones had a son David, born in 1699.
Thomas, the immigrant, died in 1713.
Andrew Meade, a Kerry Irishman, and a Catholic, emigrated to
New York, married Mary Latham, a Quakeress of Flushing, went to
Nansemond County, Va., and died there in 1745. His son was Col.
Richard Kidder Meade, an aide-de-camp of General Washington.
(Quoted by Martin I. J. Griffin of Philadelphia, Pa., in American
Catholic Historical Researches.)
Thomas, John and Walter Dongan, kinsmen of Governor Dongan
of New York, are believed to have been residing in New York in 1715.
In 1723 a private act was passed by the Assembly of the province “to
enable Thomas Dongan and Walter Dongan, two surviving kinsmen
of Thomas, late Earl of Limerick,” to sell part of their estate. A
similar act was passed in 1726.
Hotten’s Original Lists (London, 1874) contain the names of many
Irish who were conveyed to Virginia, Barbadoes and other parts. The
work comprises the period from 1600 to 1700 and mentions
“Persons of quality, emigrants, religious exiles, political rebels,
serving men sold for a term of years, apprentices, children stolen,
maidens pressed” and other wayfarers of the time.
Charles Carroll, grandfather of Charles Carroll of Carrollton, came
to this country about 1689 and settled in Maryland. In 1691 he was
made judge and register of the land office, and agent and receiver for
Lord Baltimore’s rents. His son, also named Charles Carroll, was
born in 1702 and died in 1782. Charles Carroll of Carrollton was a
son of this second Charles Carroll.
Michael Ryan, a soldier of the Revolution, was acting-adjutant of
the Fourth Pennsylvania regiment, commanded by Col. Anthony
Wayne, from Feb. 17, 1776; was appointed adjutant March 15 that
year; became a captain in the Fifth Pennsylvania, and was inspector
of General Wayne’s division; was promoted brigade-major, Nov. 18,
1777; also served as major of the Tenth Pennsylvania.
The Massachusetts records mention Patrick McMullen as serving
during the Revolution aboard the Providence, under John Paul
Jones. He is referred to as entitled to a prize share in the ship
Alexander, captured in 1777, and is also mentioned as a marine
aboard the Alfred, commanded by Jones. In this latter capacity he
was entitled to prize shares in the ship Mellish and the brig Active,
Andrew Brown, born in Ireland, was educated at Trinity College,
Dublin, came to this country and eventually settled in Massachusetts.
He was a patriot of the Revolution, fought at Lexington and Bunker
Hill; served as major under Gates and Greene. After the war, he
established the Federal Gazette at Philadelphia, Pa., the publication
being later known as the Philadelphia Gazette.
An Irish schoolmaster in Brunswick, Me., was Thomas Crowell. He
settled there shortly after the close of the Revolution, and taught
school there for over twenty years. Many of his pupils became
leading business men, and some of them famous shipmasters.
Sumner L. Holbrook read a paper, a few years ago, before the
Pejepscot Historical Society, of Brunswick, devoted to Master
Crowell.
John Donnaldson, “son of Hugh Donnaldson of Dungannon,
Ireland,” was a shipping merchant in Philadelphia, Pa.; a patriot of
the Revolution; member of the First City Troop; took part in the
battles of Trenton, Princeton, Brandywine, and Germantown;
subscribed £2,000, in 1780, in aid of the army; became register-
general of Pennsylvania; and comptroller-general of the state.
David McCarty, Albany, N. Y., was a member of the Committee of
Safety there during the Revolution. He was a valiant soldier and at
the time of his death was a general of state troops. In May, 1771, he
married Charlotta, granddaughter of Pieter Coeymans, the founder
of a wealthy Dutch family. By this marriage McCarty came into the
possession of much land in the Coeymans Patent.
Well-nigh forgotten now is Christopher Stuart, an Irishman and
soldier of the Revolution. He was born in the Old Land, 1748, and
settled in Montgomery County, Pa. He served successively as captain,
major and lieutenant-colonel of Pennsylvania troops, including the
Line; took part in the battle of Long Island, the storming of Stony
Point, and in other actions of the war; died, 1799.
Patrick Googins, “a young Irish weaver,” came to this country
about 1722 and settled at Old Orchard, Me. He married Hester
Rogers. Her father gave Patrick as her marriage portion 200 acres
there. In years long after, the place became known as “the old
Googins farm.” The farm remained in the Googins family for four
generations. (See an article in the Old Orchard Mirror, 1902.)
One of the founders of the Charitable Irish Society of Boston,
Mass., 1737, was Joseph St. Lawrence. In the records of the Boston
selectmen, that year, appears the following: “Mr. Joseph St.
Lawrence from Ireland, Merchant, having imported upwards of Fifty
Pounds Sterling, Prays he may be Allow’d to Carry on his Business in
this Town.” It is presumed the desired permission was granted.
Charles Thomson, who for nearly fifteen years was secretary of the
Continental Congress, being sometimes referred to as its “Perpetual
secretary,” was born in Ireland, 1729. He participated in various
treaty proceedings with the Indians, and was styled by the latter “The
man of truth.” He married Hannah Harrison whose nephew, William
Henry Harrison, became president of the United States.
Robert Temple arrived at Boston, Mass., from Ireland, in 1717,
with a party of Irish Protestants. He settled on Noddle’s Island, now
East Boston, and had a house there that “contained elegant rooms
suitable for the reception of persons of the first condition.” He
commanded a company in operations against the Indians. He
became a member of the Boston Charitable Irish Society in 1740.
George Taylor, a native of Ireland, died in Providence, R. I., in
1778. He taught school there for over 40 years, was for a number of
years president of the Town Council and held other positions of trust
and honor. He was a man of public spirit and witnessed events of the
earlier part of the Revolution. The Providence Gazette states that “He
was an honor to the country that gave him birth.”
Col. Israel Angell of the Second Rhode Island regiment in the
Continental Line, has this entry in his diary under date of March 17,
1781: “Good weather. A great parade this day with the Irish, it being
St. Patrick’s. I spent the day on the Point [West Point], and tarried
with the officers.” This diary has been reproduced in printed form by
Edward Field, secretary of the Providence, R. I., Record Commission.
Alexander Black, an Irishman, was a resident of Providence, R. I.,
as early as 1762. He was a merchant and was associated in business
with James Black, and later with Alexander Stewart. Alexander Black
died in Providence, 1767. In a notice of his death, which appears in
the Providence Gazette, he is declared to have been “A fast friend to
the liberties of America, and studied to promote the public weal.”
James Kavanagh, a native of County Wexford, Ireland, came to
Boston, Mass., in 1780, during the Revolution, but settled at
Damariscotta Mills, Me., and engaged in the lumber business. His
son, Edward, became president of the State Senate of Maine, a
member of Congress, United States charge d’affaires in Portugal, a
commissioner to settle the northeastern boundary of Maine, and
acting governor of Maine.
Edmund Fanning, an Irishman, was a victim of the Cromwellian
confiscation, and fled at the time of the surrender of Limerick, 1651,
and settled in Groton, Conn. His uncle, Dominick Fanning of
Limerick, was one of the 21 persons exempted from pardon by Ireton
and was beheaded at that time. D. H. Fanning and Walter F. Brooks,
Worcester, Mass., are descendants of Edmund Fanning, the Groton
settler.
Morgan Connor, a Pennsylvania soldier of the Revolution, was
successively lieutenant, captain, major, and lieutenant-colonel
commandant. He served in Col. Samuel Miles’ Pennsylvania Rifle
Regiment; was wounded in the right wrist at Princeton; was called
from camp by Congress in March, 1776, and sent South as brigade
major for General Armstrong; was afterwards lieutenant-colonel of
Hartley’s regiment.
John Brown, a native of Ireland, came to this country about 1760.
He settled in Virginia, in the Warm Spring Valley, and had a tract of
400 acres. About 1778 he married Mary Donnelly. He commanded a
company in the Revolution, and after the war was a justice for Bath
County, Va., sheriff and treasurer of the county, major of the Second
Battalion of militia, and a member of the General Assembly of
Virginia.
Daniel Dulany, a native of Queens County, Ireland, was born in
1686. He was a cousin of Rev. Patrick Dulany, dean of Down. Daniel
came to this country when quite young and settled in Maryland. He
was admitted to the bar in 1710, became attorney-general of the
province, judge of admiralty, commissary-general, agent and
receiver-general, and councillor. He was in the public service of
Maryland for nearly 40 years.
Edward Fox was born in Dublin, Ireland, 1752; came to this
country, studied law and eventually settled in Philadelphia, Pa. He
held various positions of prominence there; became secretary of the
Bank of the United States, secretary of the American Fire Insurance
Co., recorder of deeds for the county of Philadelphia, and treasurer of
the University of Pennsylvania. One of his sons married a daughter
of Gen. Stephen Moylan.
Cortlandt Schuyler of Albany, N. Y., was captain in “a marching
regiment” of the British Army. He married a handsome Irishwoman
in Ireland, while stationed there, and brought her to Albany about
1763. Upon his death, she returned to Ireland with her children,
“where it is said their desendants bearing the name Schuyler still
live.” (Mrs. Grant’s Memoirs of an American Lady, quoted by Hon.
Franklin M. Danaher of Albany.)
In 1769–’70, Rev. Hezekiah Smith made a tour of South Carolina
and Georgia in aid of Rhode Island College, now Brown University.
He says in his diary of the tour: “Thursday, March 1, 1770, went to
Malachi Murfee’s.” The list of those who subscribed in aid of the
college, on this Southern trip, includes Edward Dempsey, Charles
Reilly, Patrick Hinds, James Welsh, Hugh Dillon, John Boyd,
Matthew Roach and Capt. John Canty.
An officer who came with our French allies during the Revolution
was Isidore de Lynch. He was at one period an aide-de-camp to the
Chevalier de Chastellux. Referring to the return of the French to
Boston after the surrender of the British at Yorktown, Count Segur
speaks of “Isidore de Lynch, an intrepid Irishman, afterwards a
General.” Lynch became commander of the Irish-French regiment of
Walsh, and was decorated with the Cross of St. Louis.
The Dutch records of Albany, N. Y., mention Jan Fyne, “van
Waterfort in Irlandt.” His name likewise appears as Johannes Fine,
which in English would probably be John Finn. He is believed to
have been a soldier who was sent to Albany in 1690. He settled there
and is later mentioned as a cooper. In 1696 he wedded Jopje Classe
Van Slyck. His second wife, whom he married in 1699, was Alida,
daughter of Jacob Janse Gardiner of Kinderhook.
Watson H. Harwood, M. D., of Chasm Falls, N. Y., in a paper
contributed to the Register of the New England Historic,
Genealogical Society, January, 1898, treats of the Clogstons of New
Hampshire. He states that “The Clogston family is of Irish origin,”
and that it came to New Hampshire sometime after 1718. Paul
Clogston, a descendant of the immigrants, died of wounds received
at Bunker Hill, 1775. The name is sometimes written Clogstone.
Blair McClenachan, an Irishman by birth, settled in Philadelphia,
Pa., at an early age, and became the “largest importer in the city
except Robert Morris”; was a patriot of the Revolution; subscribed,
in 1780, £10,000 in aid of the army; was one of the original members
of the First City Troop; a member of Congress, 1797–’99; was made
commissioner of loans by President Jefferson. One of McClenachan’s
daughters married Gen. Walter Stewart.
One of the early settlers of Peterborough, N. H., was William
McNee. He was born in Ireland, 1711, and before coming to this
country married Mary E. Brownley. In an address delivered at
Peterborough, some years ago, Hon. James F. Brennan of that town
said that McNee’s “descendants have now reached the eighth
generation, but unfortunately the name is entirely lost. The first and
second generations retained the name, but the third changed it to
Nay.”
Michael Morgan O’Brien, a native of Ireland, became a West India
merchant in Philadelphia, Pa., and was located there as early as
1780. He was a member of the First City Troop of Philadelphia, of the
Friendly Sons of St. Patrick, the Hibernia Fire Company, and the
Hibernian Society. He died in France, 1804. He bequeathed his
books to the “Rt. Reverend Father in God, John Carroll, R. C., Bishop
of Baltimore, as a testimony of the great respect and esteem I bear
him.”
A prominent man in his day was John Patton. He was born in
Sligo, Ireland, 1745, settled in Philadelphia, Pa., and became a
merchant there. A patriot of the Revolution, he was successively
major and colonel of the Sixteenth Pennsylvania regiment, and
rendered gallant service during the war. In 1780 he subscribed
£1,000 in aid of the army. After the war he was an iron
manufacturer, and at the time of his death, 1804, was major-general
of Pennsylvania state troops.
Christopher Colles, a native of Ireland, was born in 1737. He came
to this country and lectured on pneumatics, inland navigation, water
supply for cities and similar topics. In 1775, he became an instructor
in gunnery and was so employed in the American Continental Army
until 1777. He memorialized the New York Legislature, in 1784, in
favor of a canal from the Hudson River to Lake Ontario. He
constructed and operated a telegraph, in 1812, at Fort Clinton.
One of the victims of the Boston massacre, March 5, 1770, was
Patrick Carr. On that date, British soldiers in Boston, Mass., fired on
a gathering of the people, three of the latter being instantly killed and
five dangerously wounded. Crispus Attucks, the leader of the
gathering, was among the killed and Carr was mortally wounded. A
granite monument stands on Boston Common to commemorate the
victims of the British. High up on the shaft, among the others,
appears the name of Patrick Carr.
The Mercury (Philadelphia) of Aug. 28, 1735, reported: “On
Monday last, Capt. Blair arrived from Carick Fargus in Ireland with
168 Irish passengers and servants and on Monday evening before
any of them landed one of them fell into the river and was drowned.”
The next paper announced: “the body was found, the next tide
carried up seven miles from the mouth of the Schuylkill.” (American
Catholic Historical Researches, Philadelphia, Pa., Martin I. J.
Griffin, editor.)
From the records of the selectmen, Boston, Mass., Aug. 4, 1736:
“Dennis Sullivant being present Informs, That he with his Wife are
lately come into this Town from South Carolina by land; That he has
been in Town about Five Weeks; That he first Lodg’d at the White
Horse Two nights, and a Fortnight at Mrs. Snowdens and now lodges
in Long lane, That he designs to return to England or Ireland, as
soon as he can Conveniently Obtain a Passage for himself and his
said Wife.”
Gen. William Thompson of the Revolution was an Irishman by
birth. He came to this country prior to the War for Independence;
served during the French and Indian War; became captain of a troop
of Light Horse; led a regiment, in 1775, to the American camp at
Cambridge, Mass., and participated in the siege of Boston; had many
sharpshooters in his command; was made brigadier-general in 1776;
relieved General Lee in command of the American forces at New
York; died in 1791.
A veteran soldier of the Revolution was Patrick Leonard, who was
born in Ireland, 1740. He came to this country and enlisted in the
Patriot ranks; served in Proctor’s artillery and in the First Regiment,
Pennsylvania Line. He saw much service and took part in the battles
of Bunker Hill, Long Island, White Plains, Trenton, Princeton,
Brandywine, Germantown and Stony Point; also served, in 1791–’96,
under Harmar, St. Clair and Wayne. He was residing, in 1817, at
Cincinnati, Ohio.
A native of County Westmeath, Ireland, John Shee, came to
America between 1742 and 1745; became prominent in Philadelphia,
Pa.; a patriot of the Revolution; commanded the Third Pennsylvania
regiment; member of the Pennsylvania State Board of War;
subscribed £1,000 in aid of the army; is referred to as “a man of
excellent manners and good acquirements”; after the war, became a
general of Pennsylvania state troops; collector of the port of
Philadelphia; city treasurer of Philadelphia.
A native of Strabane, County Tyrone, Ireland, John Dunlap, was
born in 1747. He settled in Philadelphia, Pa.; became printer to
Congress, and to the state of Pennsylvania; published the
Philadelphia Packet; was cornet, lieutenant, and commander of the
First City Troop; commanded the cavalry in the Whiskey
Insurrection campaign. During the Revolution he subscribed £4,000
in aid of the Patriot army. He was at one time the owner of 98,000
acres in the South, in addition to real estate elsewhere.
One of the earliest Irishmen in this country of whom we have
record was Francis Maguire. Hon. Hugh Hastings, state historian of
New York, writes that Maguire arrived at Jamestown, Va., with Capt.
Christopher Newport, about 1607, remained in the country nearly a
year, and returned to England with Newport. Maguire “wrote an
account of his voyage to Virginia and submitted it to the Privy
Council of Spain.” In one account he is described as an Irishman and
a Roman Catholic.
Teague Crehore was a resident of Milton or Dorchester, Mass., as
early as 1640–’50. He is stated to have been stolen from his parents
in Ireland when a child. He died in 1695, aged 55 years. This would
show that he was born about 1640. He had a son Timothy, born in
1660, who died in 1739 and is buried in Milton, Mass. This Timothy
had a son Timothy, grandson of Teague, who was born in 1689 and
wedded Mary Driscoll of Dorchester, Mass., in 1712. He died in 1755
and is buried in Milton.
Rev. Samuel Dorrance, an Irish Presbyterian clergyman, arrived in
Voluntown, Conn., 1722, and was installed as pastor of the church
there. His nationality caused some dissatisfaction, and the
disgruntled members of the church drew up a petition for his
removal. They were informed, they said, that “He came out of
Ireland” and that since his coming “The Irish do flock into town.”
(Larned’s History of Windham County, Conn., quoted by Rev. James
H. O’Donnell in his History of the Diocese of Hartford.)
The “poll list for the election of burgesses for the County of Prince
William,” Virginia, 1731, contains many Irish names, including Darby
Callahan, Edward Barry, John Mead, Thomas Conway, Samuel
Conner, Michael Regan, James Curry, Owen Gilmore, John
Murphey, William Hogan, Thomas Hicks, Michael Scanlon, John
Madden, Dennis McCarty, Thomas Jordan, Richard Higgins,
Thomas Welsh, etc. These and other names, constituting the entire
list, are set forth in Boogher’s Gleanings of Virginia History.
A gallant soldier of the Revolution, who has almost been forgotten,
was John Haslett. He was born in Ireland, came to this country and
located in Delaware; was for several terms a member of the State
Assembly; participated in the battles of Long Island and White
Plains. On one occasion, he surprised a British picket, took 36
prisoners, 60 muskets, and two pairs of colors; became colonel of a
Delaware regiment and was killed at the battle of Princeton, 1777.
His son, Joseph, became governor of Delaware.
Among the many Irish names on the roster of the Commander-in-
Chief’s Guard, during the Revolution, is that of Hugh Hagerty. He
served in a Pennsylvania regiment of the Line, and was transferred at
Valley Forge, March 19, 1778, to the Guard just mentioned. This
organization is sometimes referred to as Washington’s “Life Guard,”
and was composed of picked men. Hagerty participated in the battle
of Monmouth and other engagements of the war. (Godfrey’s recent
work on The Commander-in-Chief’s Guard.)
The Dutch records of New York mention Jan Andriessen, “the
Irishman.” Jan was at Beverwyck, now Albany, N. Y., as early as
1645. He is also referred to as “De Iersman van Dublingh.” His name
in English was probably John Anderson. In 1649 he leased a
“bouwerie” or farm. It is also known that he bought a farm and
homestead of Peter Bronck at Coxsackie, N. Y. In one document his
signature is thus attested: “This is the mark of Jan Andriessen, the
Irishman, with his own hand set.” He died in 1664.
William Hogen, also written Hogan, is heard from in Albany, N. Y.,
as early as 1692. The Dutch records state that he was from “Yrland in
de Kings county.” At a mayor’s court held in Albany, May 14, 1700,
he was deemed “convenient and fitt to be one of the fyre masters for
ye Citty.” June 25, 1700, he was on a petit jury to try an action
between two Dutchmen. He also served on a jury in 1703. In 1700
and 1704 he was elected an assessor. (Hon. Franklin M. Danaher in
Early Irish in Old Albany, N. Y.)
James Butler came from Ireland, and is heard from at Lancaster,
Mass., 1653. He became the largest landowner in what is now
Worcester County, Mass. He also owned land in Dunstable, Woburn
and Billerica, Mass. He died in 1681. His son, Deacon John Butler,
was the first child of Irish parentage born in Woburn, and settled in
Pelham, N. H., and lies buried there. (From a letter written to the
American-Irish Historical Society by Henry A. May of Roslindale,
Mass., a descendant of James Butler the immigrant.)
A resident of Yarmouth, Mass., as early as 1645, was Teague Jones,
who is stated to have been an Irishman. He was one of the men sent
from the town, in the year just mentioned, against the Narragansett
Indians. His period of service at the time was thirteen or fourteen
days. In 1667, the selectmen of “the towne of Yarmouth returne the
name of Teague Jones for not coming to meeting.” In a “rate” made
in 1676 to defray the expenses of King Philip’s War, Teague was
assessed £2 4s, as his share. He had a son, Jeremiah.
A prominent resident of Albany, N. Y., during the Revolution, was
Hugh Denniston, “a true Irishman.” For many years he conducted
the only first-class hotel and tavern there. It was the first stone house
erected in the place. Denniston was a sturdy patriot and his hotel was
a meeting place for the liberty-loving citizens of Albany. Washington
was a guest at the hotel on his visits to Albany in 1782 and 1783, and
was there presented the freedom of the city.
Charles MacCarthy was a founder of the town of East Greenwich,
R. I., 1677. Like many surnames at that period, his is variously
spelled in the records. Thus, it appears as Macarta, Macarte,
Macarty, Mecarty, Mackarte, etc. In the year mentioned, he was one
of a party of forty-eight settlers to whom a grant of 5,000 acres, to be
called East Greenwich, was made by the General Assembly of Rhode
Island. Later, the area of the town was enlarged by the addition of
35,000 acres on the western border. Charles’ will is dated Feb. 18,
1682.
The twenty-six original members of the Charitable Irish Society,
Boston, Mass., which organization was founded in 1737, were: Robert
Duncan, Andrew Knox, Nathaniel Walsh, Joseph St. Lawrence,
Daniel McFall, Edward Allen, William Drummond, William
Freeland, Daniel Gibbs, John Noble, Adam Boyd, William Stewart,
Daniel Neal, James Mayes, Samuel Moor, Philip Mortimer, James
Egart, George Glen, Peter Pelham, John Little, Archibald Thomas,
Edward Alderchurch, James Clark, John Clark, Thomas Bennett and
Patrick Walker.
Jasper Moylan was a native of the city of Cork, Ireland, and half
brother of Gen. Stephen Moylan. He was educated in France, studied
law, came to this country and attained eminence in his profession in
Philadelphia, Pa. In addition to English, he had a splendid
knowledge of the French and Spanish languages. He was a member
of the First City Troop of Philadelphia. He and his brother John, and
their half brother Stephen, were known in that city as “the three
polite Irishmen,” owing to their elegant manners. Jasper died in
1812.
Among Virginia officers in the Revolution were Maj. William
Croghan, Capt. Ferdinand O’Neal, Capt. Patrick Carnes, Capt. John
Fitzgerald, Capt. Andrew Nixon, Capt. William Barrett, Capt. John
Jordan, Capt. Lawrence Butler, Capt. James Curry, Lieut. Joseph
Conway, Lieut. Luke Cannon, Lieut. Peter Higgins, Lieut. William
McGuire, Lieut. Lawrence Manning, Lieut. John Rooney, Lieut.
Matthew Rhea, Ensign William Connor and others bearing Irish
names. Some of these subsequently attained higher rank than that
here given.
Sharp Delany, born in County Monaghan, Ireland, established
himself as a druggist in Philadelphia, Pa., about 1764. He was a
patriot of the Revolution. In 1777, he was a commissioner “to seize
the personal effects of traitors,” and in 1778, was an agent to look
after “forfeited estates.” In 1779, he was colonel of the Second
Pennsylvania regiment. He subscribed £1,000 in aid of the army in
1780; was collector of the port of Philadelphia; a member of the
Society of the Cincinnati, and occupied other honorable positions in
life.
John Hamilton, “an Irish servant-man,” was a Redemptioner or
indentured servant who, in 1752, was held by Henry Caldwell of
Chester County, Pa. Hamilton ran away that year and Caldwell
advertised to recover him. Hamilton was then about twenty-two
years of age. Caldwell offered a reward to “whoever takes up said
servant, so that his master may have him again.” Mention of the
incident is found in Karl Frederick Geiser’s recent work on
Redemptioners and Indentured Servants in the Colony and
Commonwealth of Pennsylvania.
George Taylor, one of the Irish signers of the Declaration of
Independence, was born in the Old Land, in 1716. He came to this
country when twenty years of age. Having a good education, he
advanced from the occupation of laborer in an iron foundry to the
position of clerk; married his employer’s widow, and accumulated a
generous fortune. He was a member of the Pennsylvania Assembly
for five consecutive years. In 1770, he was made a judge of the
Northumberland County Court, Pa., and was elected to Congress in
1776.
One of the first settlers of Waterford, Conn., was Thomas Butler.
He and John Butler were there about 1681. Rev. James H. O’Donnell,
now of Norwalk, Conn., says that the “name of Waterford was, no
doubt, given to their new home in honor of the old, the beautiful city
on the banks of the Suir,” in Ireland. He thinks it not unreasonable to
infer that the founders of the Connecticut Waterford were Irish
Catholics. Thomas Butler died in 1701, aged 59 years. John Butler
died in 1733, aged 80 years. Thomas was, therefore, born about 1642,
and John about 1653.
William Hibbins came from Ireland to Boston, Mass., on the Mary
and John, about 1634. He married Mrs. Anne Moore, a widow,
whose brother, Richard Bellingham, was governor of Massachusetts.
Mr. Hibbins died in 1654. His wife fell a victim to the witch-hunting
fanatics of the period and was hanged by order of the Massachusetts
authorities, in 1656. No jury could be found to convict her and she
suffered death at the hands of the General Court. She bequeathed her
property to her two sons, in County Cork, Ireland, John and Joseph
Moore. (See Cullen’s Story of the Irish in Boston.)
Molly Pitcher, “a young Irishwoman” having “a handsome,
piercing eye,” was the wife of a cannoneer in the Patriot army during
the Revolution. At the battle of Monmouth her husband was killed at
his post, whereupon Molly, who was engaged bringing water from a
spring, dropped her bucket, seized the rammer of the cannon and
taking her husband’s place continued to serve the piece of artillery.
The next morning she was presented by General Greene to
Washington, who praised her heroism and made her a sergeant. She
was placed upon the list of half-pay officers for life.
Anthony Gulliver, a native of Ireland, was born in 1619. He died at
Milton, Mass., 1706. His children were: Lydia, born 1651; Samuel,
born 1653; Jonathan, born 1659; Stephen, born 1663; John, born
1669; Elizabeth, born 1671; Nathaniel, born 1675. There were also
two other children, Hannah and Mary. The children were all born in
this country, Cullen’s Story of the Irish in Boston states that
“Anthony Gulliver was the ancestor of a large number of able and
influential men and women, who have been prominent in the history
of church and town affairs of Milton for nearly two hundred years.”
From the Calendar of Colonial State Papers: “April 1st, 1653.
Order of the Council of State. For a license to Sir John Clotworthy to
transport to America 500 natural Irishmen.” On Oct. 3, 1655, it was
ordered that “1000 Irish girls and the like number of boys of 14 years
or under,” be sent to Jamaica, “the allowance to each one not to
exceed 20 shillings.” May 22, 1656, an order was adopted “for the
transportation of 1200 men from Knockfergus in Ireland and Port
Patrick in Scotland to Jamaica.” (Quoted by Rev. James H.
O’Donnell in his History of the Diocese of Hartford, Conn.)
A Rhode Island soldier, Patrick Tracy, participated with
Montgomery in the assault on Quebec. He was of the company of
Capt. Simeon Thayer of Providence, R. I., and was killed in the
assault just mentioned. Cornelius Hagerty and Corporal James
Hayden of the company were wounded. In a work on this invasion of
Canada, reference is made to John M. Taylor, “keen as an Irish
greyhound,” who was Arnold’s purveyor and commissary in the
wilderness. Mention is also made of Lieut. William Cross, “a
handsome little Irishman, always neatly dressed,” who commanded,
on the Isle of Orleans, a detachment of some twenty men.
Among the land patents granted in New York under the English
colonial government, was one to David Mooney, 1765. The tract was
located in Washington County and comprised 2,000 acres. It was
known as the Mooney patent. The Otsego patent, 100,000 acres, was
granted to George Croghan and ninety-nine others, in 1769. Croghan
is also mentioned in connection with other patents. Michael Byrne
and others were granted the Stony Hill Tract, 18,000 acres, in 1768.
It was located in Schoharie County. The Adaquataugie patent,
26,000 acres, in Otsego County, was granted in 1770 to Sir William
Johnson, an Irishman, and others.
The rolls of the Third New York Regiment of the Line, during the
Revolution, contain a large number of Irish names. They include
Brady, Brannon, Burke, Burns, Butler, Condon, Connolly, Dempsey,
Doherty, Dunn, Flynn, Garvey, Geraghty, Gillaspy, Hickey, Hogan,
Kelly, Lyon, McCarty, McConnelly, McCord, McCormick, McCoy,
McDermot, McGinnis, McGown, McGuire, Mackey, McLaughlin,
McNeal, McQuin, Madden, Mahan, Moloy, Moore, Morris, Morrison,
Mulholand, Murray, O’Connoley, Quigley, Riley, Ryan, Sullivan,
Sweeny, Tobin, Wall, Welch and others. (Vide New York in the
Revolution, by Comptroller James A. Roberts, Albany, 1898.)
Among Irish names found in Connecticut at early periods may be
mentioned Brian Rosseter, Windsor, 1639; Thomas Dunn, New
Haven, 1647; Lawrence Ward, Branford, 1654; Thomas Welch,
Milford, 1654; John Mead, Stamford, 1656; Richard Hughes, New
Haven, 1659; Edward Fanning, Mystic, 1662; Thomas Ford,
Windsor, 1669; Richard Butler, Stratford, 1669; Hugh Griffin,
Stratford, 1669; William Meade, New London, 1669; Thomas Sha
(Shea), Sr., Stonington, 1669; Thomas Tracy, Norwich, 1669;
Timothy Ford, New Haven, 1669; Jeremiah Blake, New London,
1681; James Kelly, New London, 1682; Owen McCarty, New London,
1693.
Gen. Walter Stewart, a Pennsylvania officer of the Revolution, was
born in Ireland, about 1756. He settled in Philadelphia, Pa., espoused
the cause of the Patriots, and in 1776 was commissioned captain. He
was made an aide-de-camp to General Gates the same year. In 1777,
Stewart was commissioned colonel of the Pennsylvania State
Regiment of Foot, took part in the battles of Brandywine and
Germantown, and retired in 1786 with the rank of brevet brigadier-
general. In 1794, he was major-general of Pennsylvania state troops.
General Washington was godfather to his eldest son. (Campbell’s
History of the Friendly Sons of St. Patrick, Philadelphia.)
The Marquis de Chastellux in a tour through Connecticut, 1780,
stopped at Litchfield. His host there was a Mr. Philips. The latter
was, the Marquis tells us, “an Irishman transplanted to America,
where he has already made a fortune; he appears to be a man skillful
and adroit; he speaks with caution to strangers, and fears to
compromise himself; for the rest he is of a gayer mood than the
Americans, even a little of a joker, a kind but little known in
America.” (From Voyages de M. Le Marquis de Chastellux dans
L’Amerique, Septentrionale les annees 1780, 1781 and 1782; quoted
by Rev. James H. O’Donnell in his History of the Diocese of
Hartford.)
A prominent merchant in Philadelphia, Pa., at one period, was
James Caldwell. He was a native of Ireland. He was a patriot of the
Revolution, a member of the First City Troop, Philadelphia, and took
part with it in the campaign of 1776–’77. Campbell’s History of the
Friendly Sons of St. Patrick, Philadelphia, says that he was “one of
the six volunteers of the Troop who accompanied Colonel Reed on
December 30, 1776, from Trenton to reconnoitre the advanced posts
of the enemy, and who captured twelve British soldiers during that
expedition.” In 1780, Caldwell subscribed £2,000 to the bank that
was organized to supply the Continental army with provisions.
Rev. Mr. Lyons, an Irish clergyman of the Church of England, who
was located in Derby, Conn., was subjected to great abuse there
because of his nationality. Writing to London, May 8, 1744, he says:
“As soon as they had advice of my appointment, and from what
country I came, and, indeed, before I arrived among them, they
abused me, calling me ‘an Irish Teague and Foreigner,’ with many
other reflections of an uncivilized and unchristian kind. It would be
too tedious to record all the abuse and insults I have received in
Derby.” (Church Documents of the Protestant Episcopal Church,
quoted by Rev. James H. O’Donnell in his History of the Diocese of
Hartford.)
Patrick Ward, a lieutenant, was one of the defenders of Fort
Griswold, Conn., during the Revolution. The fort was attacked by the
British during the raid conducted by Arnold, the traitor, and after a
gallant resistance was captured by the enemy. The atrocities
committed upon the surrendered and helpless garrison, by the
British, constitutes one of the blackest chapters in the history of
warfare. The event has ever since been known as the “Massacre of
Fort Griswold.” Ward was one of the victims. On a stone over his
grave was placed this inscription: “In memory of Mr. Patrick Ward
who fell a victim to British cruelty in Fort Griswold, Sept. 6th, 1781,
in the 25th year of his age.”
Felt’s Ecclesiastical History of New England mentions William
Collins who, about 1640, accompanied a party of refugees from the
West Indies to what is now New Haven, Conn. After a time these
wayfarers dispersed “and some returned to Ireland.” Collins
afterwards taught school at Hartford, Conn., and subsequently
wedded a daughter of Anne Hutchinson who with her family had
been banished from Boston, Mass., by the intolerant Boston church,
because of her religious views. She took up her residence on the
island of Rhode Island. Later, the family removed to territory under
Dutch jurisdiction, where Mrs. Hutchinson, her son and her son-in-
law (Collins) were killed by the Indians.
An interesting tradition is told concerning George Berkeley, “the
Kilkenny scholar,” Anglican dean of Derry, and later bishop of
Cloyne. The tradition relates to his arrival at Newport, R. I., in 1729,
and is thus narrated: “The captain of the ship in which he and his
party sailed could not find the island of Bermuda, and having given
up the search for it, steered northward until they discovered land
unknown to them and supposed to be inhabited by savages. On
making a signal, however, two men came on board from Block
Island, in the character of pilots, who on inquiry informed them that
the harbor of Newport was near.” The tradition may be founded on
fact, but opinions vary concerning it.
John Mease, born in County Tyrone, Ireland, became a shipping
merchant in Philadelphia, Pa., and was a patriot of the Revolution.
He was with the force that crossed the Delaware with Washington on
the night of Dec. 25, 1776, and surprised the Hessians at Trenton. On
another occasion he was of a detail told-off to keep the fires along the
American front burning while the patriots secretly moved in another
direction to fall upon the British at Princeton. On one occasion
during the war Mease subscribed £4,000 in aid of the Patriot cause.
He was affectionately spoken of in his old age as “The last of the
cocked hats,” on account of his continuing to wear the three-
cornered hat of the Revolution.
Count Arthur Dillon, commander of the Irish-French regiment of
Dillon during the American Revolution, perished by the guillotine in
Paris, a victim to the Terror. The regiment of Dillon formed part of
the Irish brigade in the service of France, and was a most historic
corps. It dated its organization back to the previous century. Count
Dillon, above mentioned, came with his regiment to America with
our French allies and rendered valiant service. He took part in the
capture from the British of St. Eustache, Tobago and St. Christopher,
participated in the attack on Savannah and in the siege and capture
of Yorktown. He became a brigadier and marechal-de-camp, and, in
1792, was in command of a division in the French army.
In 1743 there was born in Dublin, Ireland, a boy who was destined
to take a prominent part in the American Revolution. He was
Richard Butler. He came to this country, espoused the Patriot cause,
and attained distinction as a soldier. His ability was early recognized
by Congress and, 1776, he was appointed major. In 1777 he was
commissioned colonel of the Fifth Pennsylvania; was an officer of
Morgan’s Rifle Corps, and took part in the battles of Bemis’ Heights
and Stillwater; was made colonel of the Ninth Pennsylvania;
commanded the Americans at the storming of Stony Point;
participated in the siege and capture of Yorktown. He attained the
rank of major-general and was second in command of St. Clair’s
army for operations against the Indians. He was killed in battle by an
Indian, 1791.
“Thomas the Irishman” is mentioned in the Dutch records of New
York. Thus, Hon. Peter Stuyvesant, Director-General of New
Netherland, writing to Capt. Martin Cregier, 1663, says: “Your letter
by Thomas the Irishman has just been received.” ... On Aug. 5, 1663,
Captain Cregier writes in his journal: “Thomas the Irishman arrived
here at the Redoubt from the Manhatans.” On Sept. 1, 1663, Captain
Cregier writes: “Thomas the Irishman and Claesje Hoorn arrived
with their yachts at the Kill from the Manhatans,” and on the 17th of
the same month the captain writes: “Thomas the Irishman arrived
today.” The foregoing references may be found in Documents
Relating to the Colonial History of the State of New York, edited by
Fernow, Vol. XIII, Albany, 1881.
The first president of the Friendly Sons of St. Patrick, New York
City, 1784, was Daniel McCormick, a native of Ireland. He came to
this country prior to the Revolution, and amassed a large fortune,
was one of the first directors of the Bank of New York, and was
associated with William Constable and Alexander Macomb, two
Irishmen, in extensive land enterprises. Barrett’s Old Merchants of
New York states that “Mr. McCormick was a glorious example of the
old New Yorker,” and “stuck to short breeches and white stockings
and buckles to the last.” He was a great entertainer, “gave good
dinner parties, and had choice old wines upon the table.” He is also
mentioned “as one of the most polished gentlemen of the city.” He
“was the last occupant of a first-class dwelling on Wall Street, since
devoted wholly to business.”
From the records of the selectmen, Boston, Mass., May 4, 1723:
“Whereas great numbers of Persons haue [have] very lately bin
Transported from Ireland into this Province, many of which by
Reason of the Present Indian war and the Accedents befalling them,
Are now Resident in this Town whose Circomstances and Condition
are not known, Some of which if due care be not taken may become a
Town Charge or be otherwise prejuditial to the wellfair & Prosperity
of the Place, for Remady whereof Ordered That Every Person now
Resident here, that hath within the Space of three years last past bin
brought from Ireland, or for the future Shal come from thence hither,
Shal come and enter his name and Occupation with the Town Clerk,
and if marryed the number and Age of his Children and Servants,
within the Space of fiue [five] dayes, on pain of forfeiting and paying
the Sum of twenty Shillings for Each offence***.”
Matthew Lyon, “the Hampden of Congress,” was born in County
Wicklow, Ireland, 1750. He came to this country in 1765; located in
Connecticut, and later in Vermont; participated with Ethan Allen in
the capture of Ticonderoga from the British; became adjutant of Col.
Seth Warner’s regiment; served under General Montgomery in the
campaign against Canada, 1775; became paymaster, with the rank of
captain, in Warner’s regiment; took part in the battles of Bennington
and Saratoga; became commissary-general of militia, with the rank
of colonel; was a member of the State Legislature and judge of
Rutland County, Vt.; member of Congress from Vermont from 1797
to 1801; cast the vote that made Thomas Jefferson president of the
United States; removed to Kentucky and represented that state in
Congress from 1803 to 1811.
Sarah W. Alexander, who wedded Christopher R. Perry of Rhode
Island, became the mother of Oliver H. Perry—best known as
Commodore Perry—who defeated the British in the naval battle on
Lake Erie. She was a native of Newry, Ireland, and was born in 1768.
Mackenzie, in his Life of Commodore Perry, just mentioned, says
that her friends in Ireland “Had been involved in the Irish rebellion.
She herself, had felt a lively interest in the cause of liberty, and had
listened with deep interest to every account she had heard of battles
and skirmishes in the neighborhood. She took a pleasure in
recounting ... the achievements of her countrymen and always
insisted that they were the bravest people in the world. These
narratives fired the mind of Oliver and created a desire in him to
pursue the profession of arms.” Oliver received much of his early
education from “Old Master” Kelly, an Irish school teacher at Tower
Hill, R. I.
From the records of the selectmen, Boston, Mass., Aug. 16, 1736:
“mr. James Wimble Informs That Capt. Benedict Arnold who just
arrived from Cork with Passengers, came to his House yesterday,
being Lord’s day in the afternoon, bringing with him the following
Persons, Vizt. Mr. Benja. Ellard, Gent, and his Wife and Three
Children, and a Maid Servant, Joseph Atkins, John Clark, John
Seley, Thomas Morgan, James Ellard, John Ellard, Benjamin Gillam,
Elizabeth Ellard and William Neal. Accordingly the Master Capt.
Arnold was sent for Who appear’d and gave Information, That he
came from Ireland about Twelve Weeks ago, and that he is Bound to
Philadelphia with his Passengers, Who in all, are one Hundred and
Twenty, Hopes to Sail in a few days, as soon as he can Recruit with
Water and Provisions, and Promises That the Passengers which came
ashore Yesterdy shall repair aboard again to day, The Ships name is
the Prudent Hannah.”
Gen. William Irvine of the Revolution was born near Enniskellen,
County Fermanagh, Ireland, 1741. He came to America in 1764, and
settled at Carlisle, Pa. He espoused the patriot cause, raised and
commanded the Sixth Pennsylvania regiment; commanded a brigade
at the battle of Monmouth, and when Lee’s troops were retreating,
they so impeded the advance of this gallant Irishman’s brigade that
he threatened to charge through them before he could make his way
to take an advanced position. Irvine was made a brigadier-general in
May, 1779, and was assigned to the command of the Second brigade
of the Pennsylvania Line; later he became a member of the State
Council of Censors; member of the Continental Congress; senior
major-general of Pennsylvania State troops; a presidential elector; in
charge of United States military stores at Philadelphia. He was a
member of the Friendly Sons of St. Patrick, Philadelphia. (Vide
Campbell’s History of the Friendly Sons of St. Patrick.)
William Constable was born in Dublin, Ireland, 1752; a patriot of
the Revolution; joined the Continental army as an aide to Lafayette;
prominent as a merchant in Philadelphia, Pa.; married Ann White, a
schoolmate of the wife of General Washington; removed to New York
City in 1784; also very prominent there; associated in business with
Robert Morris and Governeur Morris, the firm being known as
Constable & Co.; engaged in huge land speculations, purchasing
large tracts in New York, Ohio, Kentucky, Virginia, and Georgia;
bought in 1787, with Alexander Macomb, a tract of 640,000 acres in
New York, Constable’s share being 192,000 acres; in 1791, he and
Alexander Macomb and Daniel McCormick purchased a tract, in
New York, of some 4,000,000 acres, or about a tenth part of the
whole state. This purchase comprised the “whole of the present
counties of Lewis, Jefferson, St. Lawrence and Franklin, with parts of
Oswego and Herkimer.” On one occasion, about 1797, Constable lent
$1,000 to the fugitive Duke of Orleans in this country, which loan
was afterwards repaid by Louis Philippe. Constable was a member of
the Friendly Sons of St. Patrick, Philadelphia, and of the Hibernian
Society of that city. He was president of the Friendly Sons of St.
Patrick, New York City, in 1789–’90 and in 1795.
MEMOIR OF MATHEW CAREY.

BY HENRY CAREY BAIRD.[14]

Mathew Carey, the Philadelphia publisher, was born in the city of


Dublin, Ireland, on the 28th of January, 1760. His father,
Christopher Carey, at one time in the British navy, was subsequently
an extensive contractor for the army, through which means he
achieved an independence.
The son early evinced a passion for the acquisition of knowledge,
and in addition to some familiarity with Latin, soon became
proficient in French, without the assistance of a master. To do this,
however, he studied as much as fifteen or sixteen hours a day, hardly
allowing himself time for his meals. The peculiar orthography of his
Christian name as rendered by himself, “Mathew,” and not
“Matthew,” was the result of a philological discussion with one of his
brothers, when quite a young man, and his then arriving at a belief
that from its derivation this was the correct mode of spelling it.
When about fifteen years of age it became necessary for Mathew to
choose a trade. He was decidedly in favor of that of printer and
bookseller, which were then generally united. His father had a strong
aversion to the trade, and refused to look out a master for him, which
he did for himself, and he was accordingly apprenticed to a printer
and bookseller of the name of McDonnel. A lameness which took
place owing to the carelessness of his nurse when he was about a year
old, and which continued throughout life, was a constant drawback
to him, and interfered greatly with him in his career.
His first essay as a writer was when he was about seventeen years
old, and was on the subject of dueling, which he condemned with
great severity—the occasion being the attempt of a bookseller in
Dublin to bring about a duel between an apprentice of his own and
one of McDonnel’s. As will be seen, however, after he came to the
United States, Mr. Carey was himself a principal, and was wounded
in a duel.
His next attempt at authorship was one which involved most
serious consequences to himself, and drove him into exile. Having
directed his attention to the oppressions under which the Irish
Catholics stood, and having read every book and pamphlet on the
subject which he could procure, and with his mind filled with their
sufferings, and his indignation aroused, he, in 1779, wrote a
pamphlet entitled The Urgent Necessity of an Immediate Repeal of
the whole Penal Code against the Roman Catholics, Candidly
Considered; to which is added an inquiry into the prejudices
against them; being an appeal to the Roman Catholics of Ireland,
exciting them to a just sense of their civil and religious rights as
citizens of a free nation.
When nearly ready it was advertised for publication in a few days,
with the title page and its mottoes, and the attention of the public
was called to it by an address, couched in very strong language, and
wherein reference was made to the fact that “America by a desperate
effort has nearly emancipated herself from slavery.” It excited
considerable alarm. Parliament was then in session, and the
advertisement was brought before both houses. The publication was
denounced by an association of Roman Catholics, which, as Mr.
Carey has asserted, “partook of the general depression and servile
spirit, which a long course of oppression uniformly produces.”
This association offered a reward for the apprehension of the
author, and engaged lawyers to carry on the prosecution in case of
discovery. The authorship having become known to Mr. Carey’s
father, was to him a cause of great alarm, and efforts were made to
appease the wrath of the committee, and induce them to abandon the
prosecution by an offer to destroy the entire edition. This was of no
avail, and after being concealed for some days, Mr. Carey got on
board of a Holyhead packet and proceeded to Paris.
He carried with him a letter of introduction to a Catholic priest, by
whom he was introduced to Dr. Franklin, then the American
Minister to the French Court, and who had a small printing office at
Passy for the purpose of printing his dispatches from America. In
this office Mr. Carey was employed while this work lasted.
Afterwards he found a position with the celebrated publisher, Didot,
who was then printing some English books. While at Passy he made
the acquaintance of the Marquis de Lafayette—whose friendship at a
subsequent period became one of the most controlling influences of
his future career.
In about twelve months he returned to Dublin, and the remainder
of his apprenticeship having been purchased from McDonnel, he
engaged for a time as the conductor of a paper called the Freeman’s
Journal. Finally, on the 13th of October, 1783, his father furnished
him with the means to establish a new paper called the Volunteers’
Journal. For this work, he says, he was “miserably qualified,”
although he had “a superabundance of zeal and ardor, and a
tolerable knack and facility of scribbling.” He adds: “The paper, as
might have been expected, partook largely of the character of its
proprietor and editor. Its career was enthusiastic and violent. It
suited the temper of the times, exercised a decided influence on
public opinion; and, in very short time, had a greater circulation than
any other paper in Dublin, except the Evening Post, which had the
great merit of calling into existence that glorious band of brothers,
the Volunteers of Ireland, whose zeal and determined resolution to
assert and defend the rights of country, struck terror into the British
cabinet, and forced the ministry to knock off chains that had bound
down the nation for centuries.”
“The Volunteers’ Journal, fanning the flame of patriotism which
pervaded the land,” says Mr. Carey, “excited the indignation of the
government, which formed a determination to put it down, if
possible. A prosecution had for a considerable time been
contemplated—and, at length, the storm which had so long
threatened, burst, in consequence of a publication which appeared
on the 5th of April, 1784, in which the Parliament in general, and
more particularly the Premier, were severely attacked.”
Accordingly, on the 7th of the same month, a motion was made in
the Irish House of Commons, for an address to the Lord Lieutenant,
requesting the apprehension of Mathew Carey. He was arrested on
the 11th, and on the 19th was taken before the House of Commons,
when certain interrogatories were put to him, which he positively
refused to answer, on the ground that he was arrested by the civil
power, and being under prosecution for the supposed libel of the
Premier, he was not amenable to another tribunal. He preferred
charges against the Sergeant-at-Arms in whose custody he was. An
exciting debate arose; the Sergeant-at-Arms was justified by a large
majority, and Mr. Carey was committed to Newgate jail, Dublin,
where he remained until the 14th of May, when Parliament having
adjourned, he was liberated by the Lord Mayor. “During my stay
there,” says Mr. Carey, “I had lived joyously—companies of
gentlemen occasionally dining with me on the choicest luxuries the
markets afforded.”
Although thus freed from the clutches of Parliament, the criminal
prosecution for libel of the Premier still stood suspended over his
head. In the then inflamed state of the public mind it would have
been impossible to procure a grand jury to find a true bill against
him; but the attorney-general filed a bill ex-officio which dispensed
with the interposition of the grand jury. Mr. Carey’s means were, in a
great measure, exhausted; and, dreading the consequences of the
prosecution and a heavy fine and imprisonment, his friends thought
it best for him to leave his native country; and, “accordingly, on the
7th of September, 1784,” he says, “when I had not reached my 25th
year, my pen drove me a second time into exile.” He embarked on
board the America, Captain Keiler, and landed in Philadelphia on the
1st of November. He was induced to select Philadelphia as his new
home for the reason that he had seen notices of his examination
before the Irish House of Commons in two Philadelphia papers.
There his case was therefore known, and would probably make him
friends.
He had sold out his paper to his brother for £500, to be remitted
as soon as practicable, and he landed in Philadelphia with about a
dozen guineas in his pocket, without a relation or a friend, or even an
acquaintance, except those of the America. A most unlooked for
circumstance soon occurred which gave a new direction to his views
and changed the course of his future life. A fellow passenger of his
had brought letters of recommendation to General Washington, and
having gone to Mount Vernon to deliver them, he there met the
Marquis de Lafayette.
The conversation turning upon the affairs of Ireland, the Marquis
said he had seen in the Philadelphia papers an account of Mr. Carey’s
troubles with the Parliament, and inquired what had become of the
poor persecuted Dublin printer, when he was informed that he was
then in Philadelphia. On the arrival of the Marquis in that city, he
wrote to Mr. Carey requesting him to call upon him. Mr. Carey then
told him that upon receipt of funds from home he proposed to
establish a newspaper in Philadelphia. Of this the Marquis approved,
and promised to recommend him to his friend, Robert Morris, and
others. The next morning Mr. Carey was greatly surprised at
receiving a letter from the Marquis containing $400. “This was the
more extraordinary and liberal,” says Mr. Carey, “as not a word had
passed between us on the subject of giving or receiving, borrowing or
lending money.”
Nor was there a word in the letter about the inclosure. Mr. Carey
went to the lodgings of the Marquis, but found that he had left the
city. He wrote to him at New York expressing his gratitude in the
strongest of terms, and received a kind and friendly answer. “I have
more than once assumed, and I now repeat,” says Mr. Carey, “that I
doubt whether in the whole life of this (I had almost said)
unparalleled man, there is to be found anything which, all the
circumstances of the case considered, more highly elevates his
character.”
Although this sum was in every sense of the word a gift, Mr. Carey
always considered it as a loan, payable to the Marquis’ countrymen,
according to the exalted sentiment of Dr. Franklin, who, when he
gave a bill for ten pounds to an Irish clergymen in distress in Paris,
told him to “pay the sum to any Americans he might find in distress,
and thus let good offices go round.” Mr. Carey paid the debt in full to
Frenchmen in want, and subsequently in addition discharged it to
the Marquis; the latter only accepting it upon the urgent solicitation
of the former.
On receiving this money, Mr. Carey at once issued proposals for
the publication of the Pennsylvania Evening Herald, and the first
number was accordingly published January 25, 1785. He received
but £50 from the sale of the Volunteers’ Journal, in Dublin, his
brother having been ruined partly by the persecutions of the
government, and partly by the establishment of an opposition paper
of the same name under government patronage. The success of the
Evening Herald was not very great, and the means of the publisher
being small, on the 25th of March he took two partners, and enlarged
the paper. It, however, made but poor progress until Mr. Carey, in
August following, commenced the publication of the Debates in the
House of Assembly, a great novelty and innovation which gave the
Herald an advantage over all its contemporaries.
Party feeling in Pennsylvania ran very high at the time, and in the
course of a political controversy, he became involved in a quarrel
with Col. Eleazer Oswald, who had been an officer of artillery during
the Revolutionary War; and this difficulty resulted in a duel which
took place in January, 1786, in New Jersey, opposite to Philadelphia,
in which Mr. Carey was wounded in the thigh, from the effects of
which he did not entirely recover for many months. He, subsequently
to the duel, greatly disgusted his second and others, by performing,
as he says, “a gratuitous act of justice, which was probably one of the
best acts of my life”—that of publishing a card retracting the charges
he had made against Colonel Oswald.
In October, 1786, in partnership with five others, he commenced
the publication of the Columbian Magazine, to the first number of
which he contributed four pieces, one of which, “A Philosophical
Dream,” was an anticipation of the state of the country in 1850, in
which, strange as these predictions must have seemed at the time,
are now quite remarkable in their realization. In December, 1786,
owing to the difficulty of realizing profits from so many partners and
other causes, he withdrew. In January, 1787, he issued the first
number of the American Museum, a magazine intended to preserve
the fugitive essays that appeared in the newspapers. This
publication, sets of which, in 12 volumes, 8vo, now exist in a number
of public and private libraries, is one of great value, and presents a
graphic and truthful record of the times. It was issued for six years,
and brought to a close in December, 1792, after a hard struggle for
life.
About this time he married Miss Bridget Flahavan, the daughter of
a highly respectable citizen of Philadelphia who had been ruined by
the Revolution. Mr. Carey’s wife was an industrious, prudent,
economical woman, with, as he says, a large fund of good sense, but,
equally with himself, without means. The match was, as he
acknowledges, imprudent; but he and his wife determined to indulge
in no unnecessary expense, and they carried out this resolution

You might also like