0% found this document useful (0 votes)
62 views65 pages

Download Full Hello World Computer Programming for Kids and Other Beginners Second Edition Warren Sande PDF All Chapters

Hello

Uploaded by

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

Download Full Hello World Computer Programming for Kids and Other Beginners Second Edition Warren Sande PDF All Chapters

Hello

Uploaded by

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

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Hello World Computer Programming for Kids and


Other Beginners Second Edition Warren Sande

https://textbookfull.com/product/hello-world-computer-
programming-for-kids-and-other-beginners-second-edition-
warren-sande/

OR CLICK BUTTON

DOWNLOAD NOW

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


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

Hello Raspberry Pi Python programming for kids and other


beginners 1st Edition Ryan Heitz

https://textbookfull.com/product/hello-raspberry-pi-python-
programming-for-kids-and-other-beginners-1st-edition-ryan-heitz/

textboxfull.com

Hello App Inventor Android programming for kids and the


rest of us 1st Edition Paula Beer

https://textbookfull.com/product/hello-app-inventor-android-
programming-for-kids-and-the-rest-of-us-1st-edition-paula-beer/

textboxfull.com

Visual Basic For Kids A Step by Step Computer Programming


Tutorial Philip Conrod

https://textbookfull.com/product/visual-basic-for-kids-a-step-by-step-
computer-programming-tutorial-philip-conrod/

textboxfull.com

Visual C For Kids A Step by Step Computer Programming


Tutorial 15th Edition Philip Conrod

https://textbookfull.com/product/visual-c-for-kids-a-step-by-step-
computer-programming-tutorial-15th-edition-philip-conrod/

textboxfull.com
Cybersecurity for beginners Second Edition Meeuwisse

https://textbookfull.com/product/cybersecurity-for-beginners-second-
edition-meeuwisse/

textboxfull.com

C# Programming for Absolute Beginners Radek Vystav■l

https://textbookfull.com/product/c-programming-for-absolute-beginners-
radek-vystavel/

textboxfull.com

Research for Social Justice A Community Based


Participatory Approach Second Edition Adje Van De Sande

https://textbookfull.com/product/research-for-social-justice-a-
community-based-participatory-approach-second-edition-adje-van-de-
sande/
textboxfull.com

Law For Computer Scientists And Other Folk Mireille


Hildebrandt

https://textbookfull.com/product/law-for-computer-scientists-and-
other-folk-mireille-hildebrandt/

textboxfull.com

Python for kids a playful introduction to programming 1st


Edition Briggs

https://textbookfull.com/product/python-for-kids-a-playful-
introduction-to-programming-1st-edition-briggs/

textboxfull.com
Praise for the First Edition of Hello! World

A great book for little kids and big kids alike.


—Gordon Colquhoun, Computer Consultant, Avalon Consulting Services

Python for growing-ups.


—Dr. John Grayson, Author of Python and Tkinter Programming

A fun book to read and learn from!


—Dr. André Roberge, President, Université Sainte-Anne

The authors have created a friendly educational programming book that makes learning fun
and painless.
—Bryan Weingarten, Software Architect

I highly recommend this book!


—Horst Jens, Python Instructor and Author of Programming While Playing

Python is a wonderful language for teaching beginners to program. It is great to see a


kid-focused Python book!
—Jeffrey Elkner, Educator

If you teach your child one thing, teach her the golden rule. If you teach her two things, then
teach her the golden rule and computer programming. This book is all you need for the latter.
—Josh Cronemeyer, Senior Software Consultant, Thoughtworks

I enjoyed the interaction with Carter in the book … My students are really going to enjoy the
Digital Pet program! Reminds me of the Tamagotchi Virtual Pet that I had years ago.
—Kari J Stellpflug, Educator, Rochester Public Schools, Rochester MN

Computer programming is a powerful tool for children 'to learn learning.' … Children who
engage in programming transfer that kind of learning to other things.
—Nicholas Negroponte, One Laptop Per Child Project

Download from Wow! eBook <www.wowebook.com>


Advance Praise for the
Second Edition of Hello! World

It made programming seem as easy as frying bacon.


—Elisabet Gordon, 10th-grade student, Eagle Harbor High School

A great intro to the world of Python for everyone. This book is so much fun!
—Mason Jenkins, 7th-grade student, Myron B. Thompson Academy

For kids from 8 to 88. The book not only covers programming in Python in a fun
way, but also sets the groundwork for good practices that can be used for other
programming languages as well.
—Ben Ooms, Software Engineer, Sogeti

If you want to learn programming or teach it to a kid, this is your book.


—Cuberick.com

A very good introduction to programming for anyone, young or old, who wants to
start learning this vital and highly enjoyable skill.
—Sue Gee, I-Programmer

Warren and Carter start simply, at the beginning, and take kids or adults all the
way to making fun 2D graphical games and simulations. Python is my first choice
for a real programming language for new programmers, and using this book is a
great way to learn it. I’ve been recommending this book to my students since the
First Edition came out.
—Dave Briccetti, Software Developer and Teacher, Dave Briccetti Software LLC

Download from Wow! eBook <www.wowebook.com>


Hello World!
Second Edition
Computer Programming for Kids
and Other Beginners

WARREN SANDE
CARTER SANDE

MANNING
SHELTER ISLAND

Download from Wow! eBook <www.wowebook.com>


For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact:
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]

©2014 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in


any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15% recycled and processed without elemental chlorine.

Manning Publications Co. Development editor: Cynthia Kane


20 Baldwin Road Copyeditor: Tiffany Taylor
PO Box 261 Proofreader: Toma Mulligan
Shelter Island, NY 11964 Illustrator: Martin Murtonen
Typesetter: Marija Tudor
Cover designer: Leslie Haimes

ISBN 978-1-617290-92-3
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – EBM – 18 17 16 15 14 13

Download from Wow! eBook <www.wowebook.com>


Contents
Preface xi
Acknowledgments xvii
About this book xix

1 Getting Started 1
Installing Python 1 Starting Python with IDLE 2 Instructions,
■ ■

please 3 Interacting with Python 5 Time to program 7


■ ■

Running your first program 8 If something goes wrong 9


Our second program 12

2 Remember This: Memory and Variables 15


Input, processing, output 15 Names 17 What’s in a
■ ■

name? 21 Numbers and strings 22 How “variable” are


■ ■

they? 24 The new me 25


3 Basic Math 28
The four basic operations 29 Operators 31 Order of
■ ■

operations 31 Two more operators 33 Really big and


■ ■

really small 35

Download from Wow! eBook <www.wowebook.com>


vi CONTENTS

4 Types of Data 40
Changing types 40 Getting more information: type() 44

Type-conversion errors 44 Using type conversions 44 ■

5 Input 46
raw_input() 47 The print command and the comma

48
Inputting numbers 50 Input from the Web 52 ■

6 GUIs—Graphical User Interfaces 55


What’s a GUI? 55 Our first GUI 56 GUI input 57
■ ■ ■
Pick your
flavor 58 The number-guessing game … again 61

Other GUI pieces 62

7 Decisions, Decisions 65
Testing, testing 65 Indenting 67 Am I seeing double? 68
■ ■

Other kinds of tests 69 What happens if the test is false? 70


Testing for more than one condition 72 Using and 73 ■

Using or 74 Using not 74


8 Loop the Loop 78


Counting loops 79 Using a counting loop 81 A shortcut—
■ ■

range() 82 A matter of style—loop variable names 84 Counting


■ ■

by steps 87 Counting without numbers 89 While we’re on the


■ ■

subject … 89 Bailing out of a loop—break and continue 90


9 Just for You—Comments 94


Adding comments 94 Single-line comments 95 End-of-line
■ ■

comments 95 Multiline comments 96 Triple-quoted


■ ■

strings 96 Commenting style 97 Comments in this book 97


■ ■

Commenting out 98

10 Game Time 99
Skier 99

11 Nested and Variable Loops 104


Nested loops 104 Variable loops 106 Variable nested
■ ■

loops 107 Even more variable nested loops 108 Using nested
■ ■

loops 110 Counting calories 113


Download from Wow! eBook <www.wowebook.com>


CONTENTS vii

12 Collecting Things Together—Lists and Dictionaries 117


What’s a list? 117 Creating a list 118 Adding things to a
■ ■

list 118 What’s the dot? 119 Lists can hold anything 120
■ ■

Getting items from a list 120 “Slicing” a list 121 Modifying


■ ■

items 124 Other ways of adding to a list 124 Deleting from a


■ ■

list 126 Searching a list 127 Looping through a list 128


■ ■

Sorting lists 129 Mutable and immutable 133 Lists of lists:


■ ■

tables of data 133 Dictionaries 136


13 Functions 143
Functions—the building blocks 143 Calling a function 145 ■

Passing arguments to a function 147 Functions with more than ■

one argument 149 Functions that return a value 151


Variable scope 153 Forcing a global 156 A bit of advice on


■ ■

naming variables 157

14 Objects 159
Objects in the real world 160 Objects in Python 160 ■

Object = attributes + methods 162 What’s the dot? 162 ■

Creating objects 162 An example class—HotDog 168


Hiding the data 172 Polymorphism and inheritance 173


Thinking ahead 175

15 Modules 178
What’s a module? 178 Why use modules? 178 Buckets of
■ ■

blocks 179 How do we create modules? 179 How do we use


■ ■

modules? 180 Namespaces 181 Standard modules 185


■ ■

16 Graphics 189
Getting some help—Pygame 189 A Pygame window 190 ■

Drawing in the window 191 Individual pixels 200 Images 205


■ ■

Let’s get moving! 207 Animation 208 Smoother ■ ■

animation 210 Bouncing the ball 211 Wrapping the ball 213
■ ■

17 Sprites and Collision Detection 217


Sprites 217 ■
Bump! Collision detection 223 ■
Counting
time 228

Download from Wow! eBook <www.wowebook.com>


viii CONTENTS

18 A New Kind of Input—Events 233


Events 233 ■
Keyboard events 235 Mouse events 240 ■

Timer events 241 Time for another game—PyPong 244


19 Sound 256
More help from Pygame—mixer 256 Making sounds vs. playing ■

sounds 257 Playing sounds 257 Controlling volume 260


■ ■

Repeating music 262 Adding sounds to PyPong 263 More■ ■

wacky sounds 264 Adding music to PyPong 267 ■

20 More GUIs 272


Working with PyQt 272 Making our GUI do something 277 ■

The return of event handlers 279 Moving the button 280 ■

More useful GUIs 280 TempGUI 281 What’s on the menu?■ ■


287

21 Print Formatting and Strings 293


New lines 294 Horizontal spacing—tabs 296 Inserting variables
■ ■

in strings 298 Number formatting 299 Formatting, the new


■ ■

way 304 Strings ’n’ things 305


22 File Input and Output 313


What’s a file? 314 Filenames 314 File locations 315
■ ■

Opening a file 319 Reading a file 320 Text files and binary
■ ■

files 322 Writing to a file 323 Saving your stuff in files:


■ ■

pickle 327 Game time again—Hangman 329 Try it out 336


■ ■

23 Take a Chance—Randomness 337


What’s randomness? 338 Rolling the dice ■
338 ■
Creating a deck
of cards 343 Crazy Eights 348 ■

24 Computer Simulations 361


Modeling the real world 361 Lunar Lander 362 Keeping ■ ■

time 367 Time objects 368 Saving time to a file 372


■ ■

Virtual Pet 374

25 Skier Explained 385


The skier 385 ■
The obstacles 389

Download from Wow! eBook <www.wowebook.com>


CONTENTS ix

26 Python Battle 399


Python Battle 399 Creating a Python Battle Robot 401
■ ■
A more
complicated robot 403 The coordinate system 404

27 What’s Next? 409


For younger programmers 409 Python 410 Game
■ ■

programming and Pygame 410 Other game programming


(non-Python) 411 Keep it BASIC 411 Mobile apps 411


■ ■

Look around 411

Appendix A Variable Naming Rules 413


Appendix B Differences Between Python 2 and 3 415
Appendix C Answers to Self-Test Questions 419
List of Code Listings 451
Index 455

Download from Wow! eBook <www.wowebook.com>


Download from Wow! eBook <www.wowebook.com>
Preface
The preface is that part at the beginning of a book that you skip over to get to the good
stuff, right? Sure, you can skip over it if you want (hey, you’re the one turning the pages),
but who knows what you might miss…. It’s not very long, so maybe you should give it a
look, just in case.

What is programming?
Very simply, programming means telling a computer to do something. Computers are dumb
machines. They don’t know how to do anything. You have to tell them everything, and you
have to get all the details right.

Duhhhhhhhhh…

xi

Download from Wow! eBook <www.wowebook.com>


xii PREFACE

But if you give them the right instructions, they can do many wonderful and amazing
things.

An instruction is a basic command you give to a


computer, usually to do a single, very specific thing.

A computer program is made up of a number of instructions. Computers do all the great


things they do today because a lot of smart programmers wrote programs or software to
tell them how. Software just means a program or collection of programs that run on your
computer, or sometimes on another computer yours is connected to, like a web server.

Computers “think” using lots and lots


and LOTS of electrical circuits. At
the most basic level, these circuits
are switches that are either ON or
OFF.

Engineers and computer scientists use


1 and 0 to stand for ON and OFF. All
these 1s and 0s are a kind of code
called binary. Binary really just
means “two states.” The two states
are ON and OFF, or 1 and 0.

Did you know: binary digit = bit.

Python—a language for us and the computer


All computers use binary inside. But most people don’t speak binary very well. We need an
easier way to tell the computer what we want it to do. So people invented programming
languages. A computer programming language lets us write things in a way we can
understand, and then translates that into binary for the computer to use.

Download from Wow! eBook <www.wowebook.com>


PREFACE xiii

1110001101
0001110011
0100101000

No, no, no!


I only speak
human-ese!

>>> print “Hello”


Hello Ah! Now I
About
get it! Hello! time!

There are many different programming languages. This book will teach you how to use one
of those languages—one called Python—to tell the computer what to do.

We highly recommend using the Hello World installer, which installs the correct version of
Python you need to use this book. You can find it at www.helloworldbook2.com.

Why learn programming?


Even if you don’t become a professional programmer (most people don’t), there are lots of
reasons to learn programming:
■ The most important is because you want to! Programming can be very interesting and
rewarding, as a hobby or a profession.
■ If you’re interested in computers and want to know more about how they work and
how you can make them do what you want, that’s a good reason to learn about pro-
gramming.
■ Maybe you want to make your own games, or maybe you can’t find a program that
does exactly what you want or need it to do, so you want to write your own.

Download from Wow! eBook <www.wowebook.com>


xiv PREFACE

■ Computers are everywhere these days, so there’s a good chance you’ll use computers
at work, at school, or at home—probably all three. Learning about programming will
help you understand computers better in general.

Why Python?
With all the programming languages to choose from (and there are a lot!), why did I pick
Python for a programming book for kids? Here are a few reasons:
■ Python was created from the start to be easy to learn. Python programs are about the
easiest to read, write, and understand of any computer language I have seen.
■ Python is free. You can download Python—and many, many fun and useful programs
written in Python—for free.
■ Python is open source software. Part of what open source means is that any user can
extend Python (create things that let you do more with Python, or do the same things
more easily). Many people have done this, and there is a large collection of free
Python stuff that you can download.
■ Python isn’t a toy. Although it’s very good for learning programming, it’s also used by
thousands of professionals around the world every day, including programmers at
institutions like NASA and Google. So once you learn Python, you don’t have to switch
to a “real” language to make “real” programs. You can do a lot with Python.
■ Python runs on different kinds of computers. Python is available for Windows PCs,
Macs, and computers running Linux. Most of the time, the same Python program that
works on your Windows PC at home will work on the Mac at your school. You can use
this book with virtually any computer that has Python. (And remember, if the com-
puter you want to use doesn’t have Python, you can get it for free.)
■ I like Python. I enjoy learning it and using it, and I think you will, too.

prin
: pyp
'Usage rint f (0)class # Increment th
t > >>
if #

ful message if len(sy .exit


print
nt
help pri 'sys
e pa
>>>H

Hello
f#

s ge
prin
ello i
ile

ta me
t >>>
if #

c
na
2:

Hello
.ar
v)!=
n

oun
were given, pri

Thinking like a programmer


t

d rese
, an

We’re using Python in this book, but


t th
e line co self.header

most of what you’ll learn about pro-


ents

m
argu gramming here can be used with any
u
no
nt

computer language. Learning to program


If

#
string e,
tim with Python will give you a great start
ort sys,

_wr

on almost any other language you want tte


i

n=If no If
to use in the future.
n o ar
=1 ; #
imp

nt u
.co

er der hon
hea

v pyt

gu

and foot f
!/

me
#P bin sel nts
a

agin /env arguments 1 ;


ing ate a !/bin/en #
text file, add

Download from Wow! eBook <www.wowebook.com>


PREFACE xv

The fun stuff


There’s just one other thing I need to mention
now….

For kids especially, one of the most fun parts of


using a computer is playing games, with graphics
and sound. We’re going to learn how to make our
own games and do lots of things with graphics and
sound as we go along. Here are pictures of some of
the programs we’ll be making:

Download from Wow! eBook <www.wowebook.com>


xvi PREFACE

But I think (as least, I hope) you’ll find learning the basics and writing your first programs as
enjoyable and rewarding as making those spaceships or skiers zoom around the screen.

Have fun!

Download from Wow! eBook <www.wowebook.com>


Acknowledgments
This book would never have been started, much less finished, without the inspiration, initia-
tive, and support of my wonderful wife, Patricia. When we couldn’t find a suitable book to
feed Carter’s keen interest in learning about programming, she said, “You should write one.
It would be a great project for you two to work on together.” As is often the case, she was
right. Patricia has a way of bringing out the best in people. So Carter and I started thinking
about what would be in such a book, writing chapter outlines and sample programs, and
finding ways to make it fun and interesting. Once we got started, Carter and Patricia made
sure we finished. Carter would give up bedtime stories to work on the book. And if we
didn’t work on it for a while, I would be reminded, “Daddy, we haven’t worked on the book
for days!” Carter and Patricia reminded me that, if you put your mind to it, you can do any-
thing. And all members of the family, including our daughter Kyra, gave up many hours of
family time while the book was in progress. I thank all of them for their patience and loving
support, which made this book possible.

Writing a manuscript is one thing; getting a book into people’s hands is another. This book
would never have been published without the enthusiastic and persistent support of
Michael Stephens at Manning Publications. Right from the start, he “got it” and agreed that
there was a need for this kind of book. Michael’s steadfast belief in the project and his con-
tinued patience in guiding a rookie author through the process were immensely valuable
and appreciated. I would also like to say a sincere thank you to all the other folks at Man-
ning who helped make this book happen, in particular Mary Piergies for patiently coordi-
nating all aspects of the production process.

xvii

Download from Wow! eBook <www.wowebook.com>


xviii ACKNOWLEDGMENTS

This book would not be the same without Martin Murtonen’s lively and fun illustrations. His
work speaks for itself about Martin’s creativity and talent. But what doesn’t show is how
great he is to work with. It was a pleasure.

One day, I asked my friend and colleague Sean Cavanagh, “How would you do this in Perl?”
Sean said, “I wouldn’t. I would use Python.” So I took the plunge to learn a new program-
ming language. Sean answered many questions when I was learning Python and reviewed
early drafts. He also created and maintains the installer. His help is much appreciated.

I would also like to thank the many people who reviewed the book during its development
and helped prepare the manuscript: Vibhu Chandreshekar, Pam Colquhoun, Gordon
Colquhoun, Dr. Tim Couper, Josh Cronemeyer, Simon Cronemeyer, Kevin Driscoll, Jeffrey
Elkner, Ted Felix, David Goodger, Lisa L. Goodyear, Dr. John Grayson, Michelle Hutton, Horst
Jens, Andy Judkis, Caiden Kumar, Anthony Linfante, Shannon Madison, Kenneth McDonald,
Evan Morris, Prof. Alexander Repenning, André Roberge, Kari J. Stellpflug, Kirby Urner, and
Bryan Weingarten

The final result is much better for their efforts.


WARREN SANDE

I would like to thank Martin Murtonen for his exceptional caricature of me, my mom for
letting me go on the computer when I was two years old and for coming up with the idea of
writing a book, and, most importantly, my dad for all the effort he put into this book with
me and showing me how to program.
CARTER SANDE

Acknowledgments for the Second Edition


In updating Hello World!, many of the same people contributed who helped with the First
Edition. In addition to those people listed previously, we’d like to thank those who helped
review the Second Edition during its development: Ben Ooms, Brian T. Young, Cody
Roseborough, Dave Briccetti, Elizabet Gordon, Iris Faraway, Mason Jenkins, Rick Gordon,
Shawn Stebner, and Zachary Young. Thanks also to Ignacio Beltran-Torres and Daniel Soltis
who did a careful technical proofread of the final manuscript shortly before it went into
production.

We’d also like to thank all the folks at Manning who helped make this Second Edition of
Hello World! even better than the original.

Download from Wow! eBook <www.wowebook.com>


About this book
This book teaches the basics of computer programming. It’s meant for kids, but anyone who
wants to learn how to program a computer can use it.

You don’t need to know anything about programming to use this book, but you should
know the basics of using your computer. Maybe you use it for email, surfing the Web, listen-
ing to music, playing games, or writing reports for school. If you can do the basic things on
your computer, like starting a program and opening and saving files, you should have no
trouble using this book.

What you need


This book teaches programming using a computer language called Python. Python is free,
and you can download it from several places, including this book’s web site. To learn pro-
gramming using this book, all you need are
■ This book (of course!).
■ A computer with Windows, Mac OS X, or Linux on it. The examples in this book are
done in Windows. (There is some help for Mac and Linux users on the book’s web site:
www.helloworldbook2.com.)
■ Basic knowledge of how to use your computer (starting programs, saving files, and so
on). If you have trouble with this, maybe you can get someone to help you.
■ Permission to install Python on your computer (from your parent, your teacher, or
whoever is responsible for your computer). We highly recommend using the Hello World

xix

Download from Wow! eBook <www.wowebook.com>


xx ABOUT THIS BOOK

installer, which installs the correct version of Python you need to use this book. You
can find it at www.helloworldbook2.com.
■ The desire to learn and try things, even if they don’t always work the first time.

What you don’t need


To learn programming with this book, you don’t need
■ To buy any software. Everything you need is free, and a copy is available on the book’s
web site, www.helloworldbook2.com.
■ Any knowledge of computer programming. This book is for beginners.

Using this book


If you’re going to use this book to help you learn programming, here are a few pointers that
will help you get more out of it:
■ Follow along with the examples.
■ Type in the programs.
■ Do the quiz questions.
■ Don’t worry, be happy!

Follow along with the examples


When you see examples in the book, they’ll look like this:

if timsAnswer == correctAnswer:
print "You got it right!"
score = score + 10

Always try to follow along and type the programs in yourself. (I’ll tell you exactly how to do
it.) You could just sit in a big, comfy chair and read this whole book, and you’d probably
learn something about programming. But you’ll learn a whole lot more by doing some
programming.

Installing Python
To use this book, you need to have Python installed on your computer. We highly
recommend using the Hello World installer, which installs the correct version of Python,
plus a few other things you’ll need. The Hello World installer is available at the book’s
web site: www.helloworldbook2.com.

Download from Wow! eBook <www.wowebook.com>


ABOUT THIS BOOK xxi

If you install Python using some other method, and you don’t get the right version of
Python and the other modules you need, you might get frustrated when some things don’t
work like they should.

Type in the programs


The installer program that goes with this book will copy all the example programs to your
hard drive (if you want). The installer is on the book’s web site: www.helloworldbook2.com.
You can also view and download individual examples from the web site, but I encourage
you to type as many of them yourself as possible. Just by typing the programs, you’ll get a
“feel” for programming and for Python in particular. (And we can all use more typing
practice!)

Do the quiz questions


At the end of every chapter, there are some questions to practice what you’ve learned. Do
as many as you can. If you’re stuck, try to find someone who knows about programming to
help you. Work through them together—you’ll learn a lot by doing that. Don’t peek at the
answers until you’re done, unless you’re really, really stuck. (Yes, some of the answers are in
the back of the book and on the web site, but like I said, don’t peek.)

Hey, mon! Chill.


You can’t break the
computah’, so just
give it a try.

Don't worry about making mistakes.


In fact, make lots of them! I
think making mistakes and figuring
out how to find them and fix them is
one of the best ways to learn.

In programming, your mistakes don't usually


cost you anything except a bit of time. So
make lots of them, learn lots from them, and
have fun.

Download from Wow! eBook <www.wowebook.com>


xxii ABOUT THIS BOOK

Carter says I’m Carter.


I haven't noticed
I wanted to make sure this book was good for
anything unusual... yet!
kids—fun and easy to understand. Luckily, I had Just wanted to
some help. Carter is a kid who loves computers say hi!
and wants to learn more about them. So he
helped me to make sure I got this book
right. When Carter noticed something
funny or unusual, or something that didn’t
make sense, we show it like this, at right:

What’s new in the Second Edition


First, let’s talk about what didn’t change. We decided to stay with Python 2 for Hello World!,
Second Edition, rather than switching to Python 3. The reasons for this are explained in
Chapter 1.

Now, here’s what’s new in the Second Edition, compared to the First Edition:
■ Everything is in color! This includes colorized code listings, which should make
reading and understanding the code even easier.
■ We added notes throughout the book explaining the differences between Python 2
and Python 3.
■ We added a section on Python dictionaries in Chapter 12.
■ For the GUI programing in Chapter 20, we switched from PythonCard, which is no
longer supported, to PyQt, which is much more widely used. PyQt is also used for
the Hangman program in Chapter 22 and the Virtual Pet program in Chapter 24.
■ We added a chapter (25) explaining in detail the Skier program, which is presented
without much explanation in Chapter 10.
■ We added a chapter (26) about writing an artificial intelligence (AI) robot that
competes against other AIs in a simple battle game.
■ We added an appendix listing differences between Python 2 and Python 3.
■ We added a list of code listings in the back of the book, before the index.

Download from Wow! eBook <www.wowebook.com>


ABOUT THIS BOOK xxiii

Talk to the authors


You can post comments and ask questions in the book’s Author Online forum at
www.helloworldbook2.com.

Note to parents and teachers


Python is free, open source software, and there is no danger in installing and using it on
your computers. You can get the Python software—and everything else you need to use
this book—for free at www.helloworldbook2.com. The download files are simple to install
and use and are free of viruses and spyware.

Books like this used to come with CDs with all the software on them, but now most readers
(and publishers) prefer to use the Internet. If you can’t download the software from the
book’s web site, Manning can send you a CD containing the same files available on the web
site. There’s no cost for the CD, but you’ll have to pay the shipping and handling fee based
on your address.

To get the CD, send an email to [email protected] with the subject line “Hello World!
2nd Edition CD.” Or you can send a good, old-fashioned letter to:

Hello World 2nd Edition CD Request


Manning Publications Co.
20 Baldwin Road
P.O. Box 761
Shelter Island, NY 11964

Resources for this book and access to the Author Online forum are also available from the
publisher’s website at www.manning.com/HelloWorldSecondEdition.

Download from Wow! eBook <www.wowebook.com>


xxiv ABOUT THIS BOOK

Download from Wow! eBook <www.wowebook.com>


C H A P T E R 1

Getting Started
Installing Python
The first thing you need to do is install Python on the computer you’re going to use.

Installing Python is pretty easy. We highly recommend using the Hello World installer, which
installs the correct version of Python you need to use this book. You can find it at
www.helloworldbook2.com. Find the version of the installer that matches your computer’s
operating system.

In the early days of personal computers (PCs), people had it easy. With
a lot of the first PCs, a programming language called BASIC was built
in to the computer. They didn’t have to install anything. All they did
was turn on the computer, and the screen would say “READY,” and
they could start typing BASIC programs. Sounds great, huh?

Of course, that “READY” was all you got. No programs, no


windows, no menus. If you wanted the computer to do
anything, you had to write a program! There were no word
processors, media players, web browsers, or any of the
things we are used to now. There wasn’t even a Web to
browse. There were no fancy graphics and no sound,
except the occasional “beep” if you made a mistake!

Download from Wow! eBook <www.wowebook.com>


2 Hello World!

There are versions for Windows, Mac OS X,


and Linux. All the examples in this book
If Python is al
use Windows, but using Python in Mac OS X ready installe
computer, an d on your
or Linux is very similar. Just follow the d you are no
use the instal t going to
ler, you will ne
instructions on the web site to run the make sure th ed to
at some “ext
you’ll need fo ras” that
right installer for your system. r this book ar
e also
installed. Hav
e a look at th
installation se e
The version of Python that we use in this book ction of the w
(www.hellow eb site
orldbook2.c
is version 2.7.3. If you use the installer on the find out how om) to
to do this. Bu
book’s web site, that’s the version you’ll get. By the best way t again,
to make sure
code in the bo all the
the time you read this, there might be newer ok will work
correctly is to
use our instal
versions of Python out there. All the examples which you ca ler,
n find at
in this book have been tested using Python www.hellow
orldbook2.c
om.
2.7.3. They’re likely to work with later 2.x
versions as well, but we can’t see into the
future, so there are no guarantees.

Python 2 vs. Python 3


A few years before this book was written, a new version of Python
was released, Python 3. However, it turned out that it wasn’t really an
“upgrade” so much as a fork in the road. That is, many people did not
want to switch to Python 3, so they stayed with Python 2. The folks
who develop Python kept making new versions of Python 2 as well as
new versions of Python 3. At the time this Second Edition of “Hello
World!” was written, the two current versions of Python were Python
2.7.3 and Python 3.3.0. This book uses Python 2.7.3, and the code is
likely to be compatible with any future versions of Python 2.x.

For more details on Python 2 vs. Python 3, see appendix B.

Starting Python with IDLE


There are a couple of ways to start using Python. One is called IDLE, and that’s the one we’ll
use for now.

Download from Wow! eBook <www.wowebook.com>


CHAPTER 1 Getting Started 3

In the Start menu, under Python 2.7, you’ll see IDLE (Python GUI). Click this option, and the
IDLE window will open. It should look something like the window below.

IDLE is a Python shell. A shell is basically a way of


interacting with a program by typing text, and
GUI stands for graphical user
this shell lets you interact with Python. (That’s
interface. This means something
why you see Python Shell in the title bar of the with windows, menus, buttons,
window.) IDLE also happens to be a GUI, which scrollbars, etc. Programs
that don’t have a GUI are
is why it says Python GUI in the Start menu. called text-mode programs,
IDLE has some other things besides the shell, console programs, or
command-line programs.
but we’ll get to all that in a minute.

The >>> in the previous figure is the Python prompt. A prompt is what a program displays
when it’s waiting for you to type something. The >>> prompt tells you that Python is ready
for you to start typing Python instructions.

Instructions, please
Let’s give Python our first instruction. With the cursor at the end of the >>> prompt, type

print "Hello World!"

and press the Enter key. (On some keyboards, this is called the Return key.) You need to
press the Enter key after every line you type.

After you press the Enter key, you should get this response:

Hello World!
>>>

Download from Wow! eBook <www.wowebook.com>


4 Hello World!

The figure below shows how that looks in the IDLE window.

Python did what you told it: it printed You are


your message. (In programming, print now under my
often means to display text on the screen, command! >>> YES MASTERRRRR...
instead of printing it on a piece of
paper using your printer.) That
one line is a Python instruction.
You’re on your way to
programming! The computer
is under your command!

By the way, in learning to


program, there is a tradition that

the first thing you make the computer do is dis-


Why are there play “Hello World!” That’s where the title of this
all those fancy colors
book comes from. You’re following that tradi-
in IDLE?
tion. Welcome to the world of programming!

Good question! IDLE is trying to help you understand


things a bit better. It’s showing things in different colors to help
you tell different parts of the code apart. (Code is just another term for
the instructions you give to the computer in a language like Python.)
I’ll explain what the different parts are as we go through the rest of
this book.

Download from Wow! eBook <www.wowebook.com>


Another Random Scribd Document
with Unrelated Content
LETTER MXCVII
TO Mr. V――.

Weston-Favell, August 30, 1755.

My dear Friend,

I WROTE you a letter just before I left Charles-Town, which I find


you have not received. The things sent proved bad, but I have a
God to go to, who can and will supply all my wants according to the
riches of his grace in Christ Jesus. I am sorry that your people
continue yet as sheep having no shepherd. What I said about Mr.
B――, was by commission from himself, I wish Mr. D―― may see his
way clear. But who will come to be torn in pieces by two contending
parties?

Giver of concord, prince of peace,

Meek lamb-like Son of God,

Bid these unchristian jarrings cease,

O quench them with thy blood!

Amidst all this, what a mercy is it, my dear friend, that Jesus shews
you more of your heart. O thank him a thousand and a thousand
times, for pointing out to you the sin that doth most easily beset
you. Surely it is a too great love of money. Of this your friends every
where take notice; and this, in many cases, makes you act an
unfriendly part. If God should suffer our enemies to prevail, you will
wish you had laid up more treasure in heaven. Blessed be God, mine
is out of the reach of men or devils. Strange! that five per cent. from
man, should be preferred to a hundred-fold from Christ! A word to
the wise is sufficient. I should not have said this, lest there should
be the appearance of self-interest, had you not given me the hint.
But I hope you know, (however, I am sure that God knows) that I
want to deny, not enrich myself. But enough of this. I am now
looking out for more news from dear America. May the late defeat
be sanctified; and then I doubt not but we shall be more than
conquerors through the love of Christ. I often wish myself abroad;
but assuredly Providence called me home.—My poor feeble labours
are still blessed both in town and country, and many dear ministers
of Jesus are coming out. It would delight you to be at Tabernacle. We
are often in the suburbs of heaven. I write this from dear Mr.
H――y’s, in my way to Yorkshire, and perhaps Ireland, I told him
what you wrote about Theron and Aspasio, and he begs your
prayers. O America, how near dost thou lie upon my heart! God
preserve it from popish tyranny and arbitrary power! I can write no
more. Adieu, my dear Mr. V――. Continue to write to me, and live
and give for Jesus, who hath given you this world, and that which is
to come. Was you here, methinks we should weep together. O
redeeming love! How can we think of it, and at the same time not be
ambitious of opportunities to spend and be spent for Jesus. Non
magna loquimur, non magna scribimus, sed vivimus, is the christian’s
motto. Mr. D―― can English it. I send to him, and all enquiring
friends, my cordial respects. I saw his daughter well at Braintree a
little while ago. There, as well as elsewhere, we had blessed
seasons. I know you will join in crying Grace! grace! with, my dear
Gaius,

Yours most affectionately in our common Lord,

G. W.

LETTER MXCVIII.
To Mr. J―― S――.

Northampton, September 1, 1755.

A ND did my dear Mr. S―― direct a letter and not send me one
line at a venture? Well, I thank him even for the direction, as
well as for all other unmerited favours. O that it was in my power to
shew my gratitude in a substantial manner! This is my comfort, God
is a prayer-hearing, promise-keeping God. He will not fail those, who
have confessed him or his ministers before men.—It may be, before
men they shall be rewarded. Certain it is, they shall be confessed by
Jesus Christ in the presence of men and angels in the kingdom of
heaven. This, ere long, will be your happiness. Methinks I long for
the day; but am ashamed I do no more for Jesus, who yet continues
to employ me. Every where the fields are white ready unto harvest.
At London, Bristol, Bath, in Gloucestershire, at Norwich, Bury,
Braintree, and yesterday twice here, we had blessed seasons. I am
now going into Yorkshire, and it may be to Ireland. If there should
be a bloody war, God only knows when I shall see my dear New-
England. Thither I find a strong attraction. O for good news from the
northern forces! I suppose death must come first before life.—This is
always the method of Providence. Lord, help us to pray and not
faint! Happy they who have got a Jesus to fly to: he is our refuge
from every storm. Your whole self and all enquiring friends do I most
earnestly commend to his never-failing mercy, as being, my very
dear Sir,

Yours most affectionately in our common Lord,

G. W.

LETTER MXCIX.
To Colonel P――.

Northampton, September 1, 1755.

My dear Sir,

A CCORDING to my promise, before I embarked for England, I


sent you the copy of my oath, from Charles-Town; which, I fear,
is not come to hand, because not mentioned in either of your letters,
which I had the pleasure of receiving a few days ago. In my way
northward, I take the first opportunity of thanking you for both, and
at the same time heartily thank the Captain of our salvation, for
giving you grace to stand to your colours, and persist in your
spiritual warfare. Perhaps, ere this reaches Boston, you may be
called out in the service of your country. May your head, and the
heads of all engaged, be covered in every day of battle; and may
our troops be made in the end more than conquerors through the
love of God! This is what we are assured of in our spiritual combat.—
Jesus, who is truth itself, hath told us, that nothing shall pluck us out
of his almighty hands. Though faint then, let us still pursue. Through
the Redeemer strengthening me, I am yet continuing my feeble
labours, which, I trust, are not in vain in the Lord. Fain would I be
with you; but Providence seems to have cast my lot at present here.
Well, my dear Sir, there is a place, at which, though absent from, we
may be present with each other; I mean the throne of grace. There,
God willing, I will often meet you. I know you will accept the
challenge, and God himself will say, Amen. Glad should I be to hear
from you frequently. O for good news from dear New-England!
Blessed be God for what you send me concerning Mrs. P――. May
root and branch be spared for the Mediator’s glory! To his tender,
never-failing mercy, do I most humbly commend you, and all other
enquiring friends, as being, my dear Sir,

Your most affectionate friend and ready servant for Christ’s


sake,
G. W.

LETTER MC.
To Mrs. M――.

Liverpool, Sept. 12, 1755.

Dear Madam,

E RE this can reach you, I hope the days of your mourning will be
ended. By your last to Mr. W―― I find your harp was hanging
upon the willows, your chariot wheels taken off, and your poor soul
driving heavily. Add to all this,—Satan was besetting you on every
side, and so daring as to say, “Where is now thy God?”—This is his
common artifice; thus he attacked the great High-priest and blessed
apostle of our profession, “If thou be the Son of God, &c.” But if you
love not Jesus, whence this pain of absence? Why so often crying
out,

For to my soul it’s hell to be

But for one moment void of thee?

This is not the language of a hypocrite. No: it is the native, genuine


cry of a new and heaven-born soul. Woman, therefore, why weepest
thou? Thy Lord hath drank of this bitter cup before thee.

He knows what this temptation means,

For he hath felt the same.


Look then to Him, dear Madam, who upon the cross cried out in the
bitterness of his soul, “My God, my God, why hast thou forsaken
me?” The Redeemer is now only giving you blessings in disguise,
and teaching you instructive lessons by the thorns and briars of the
wilderness. Now is the time for you to prove the strength of Jesus
yours, and to learn to live upon a God that changeth not. Be pleased
to excuse this freedom. At Mr. W――d’s desire I take it. Your advice
to him, amidst all your gloom, bespeaks your concern for the ark of
God; I wish he may take it. But I love not to interfere in other
people’s plans, any further than I can contribute a mite towards
promoting the common salvation. This principle made me incline to
see Ireland, but I believe the season is too far gone. The
Redeemer’s time is best. O that all may have grace given them to
wait his leisure! Then will affairs have a more comfortable aspect,
and many wrong touches of the ark be happily prevented. Blessed
be God, in many places the word runs and is glorified. O that I could
begin to begin to do something for Jesus! I wish that Mr. C―― may
be raised to work for him once more. And yet, methinks it is cruel to
wish him to stay longer out of heaven. God give me patience to wait
till my wished-for change shall come! My cordial respects await all
that love Christ Jesus in sincerity.—Be pleased to accept the same for
your whole self, from, dear Madam,

Your sympathizing friend, and ready servant, for Christ’s


sake,

G. W.

LETTER MCI.
To Mr. S――.

Newcastle, September 24, 1755.


My very dear Sir,

A T length I can sit down, and send you (what I know you dearly
love) some good news concerning the kingdom of Jesus Christ.
O infinite condescension! He hath vouchsafed to own and bless my
feeble labours all the way. At Northampton we had blessed seasons;
at Lady H――n’s, the Lord of all Lords was with us of a truth; at
Liverpool I trust some fallow ground was broken up; at Bolton the
cup of many ran over; at Manchester people heard most gladly; and
at Leeds and Bradford, what many felt, I believe, is unutterable. In
my way hither, I hope a smart gentleman was touched at York, and
several I find were awakened when I was at this place last. Lord,
what am I?

If thou excuse, then work thy will,

By so unfit an instrument;

It will at once thy goodness shew,

And prove thy power omnipotent.

What God does further, you may hear by and by. Perhaps I am at the
end of my northern circuit, and I fear I am too impatient to get at
the end of my christian race. I long, I long to see Jesus. Well, he that
comes, will come and will not tarry. His reward is with him; then, but
not till then, shall you and yours be fully recompensed, for
strengthening my poor feeble hands in the Lord. He only knows how
feeble. Surely this is grace indeed, to employ such a wretch as I am.
Help me to adore it. Continue to pray for me, and thereby add to the
obligations already conferred on, my very dear friend,

Yours most affectionately in our common Lord,

G. W.
LETTER MCII.
To Lady H――n.

Newcastle, September 24, 1755.

Ever-honoured Madam,

I KNOW not how long it is since I left your Ladyship; but this I
know, a sense of the satisfaction I felt when at ♦Donnington, still
lies upon my heart. Surely, was I not called out to public work,
waiting upon and administring to your Ladyship in holy offices would
be my choice and highest privilege. But Jesus calls, and therefore I
travel to do or suffer thy will, O God! The only new ground that hath
been broken up, I think is Liverpool; there the prospect is promising.
I preached in a great square on the Lord’s day, and the alarm I hear
went through the town. At Bolton the cup of God’s people ran over;
and at Manchester we had large auditories and blessed seasons. At
Leeds we felt what is unutterable, and at Bradford, I believe, last
Sunday the congregation consisted of at least ten thousand. But O
how hath my pleasure been alloyed at Leeds! I rejoiced there with
trembling; for unknown to me, they had almost finished a large
house in order to form a separate congregation. If this scheme
succeeds, an awful separation I fear will take place amongst the
societies. I have written to Mr. W――, and have done all I could to
prevent it. O this self-love, this self-will! It is the devil of devils. Lord
Jesus, may thy blessed spirit purge it out of all our hearts! But O how
must the divine Paraclete sit as a refiner’s fire upon the heart, in
order to bring this about! Few choose such fiery purgations, and
therefore so few make the progress that might justly be expected of
them in the divine life. Make me, O God, willing to be made, willing
to be, to do, or suffer what thou pleasest, and then――what then?—
this foolish fluttering heart will sweetly be moulded into the divine
image.—This I write from Newcastle, where the people twice a day
hear the gospel gladly. At York I hope a fine gentleman was touched,
and several I find were awakened there, and here also, at my last
visit. What to do now, I know not. Calls on all sides are very loud,
and it is too late to go either to Ireland or Scotland. O my God!—
Winter is at hand, and in the summer how little hath been done for
thee! I cannot bear to live at this poor dying rate. My good and ever-
honoured Lady, add; for Christ’s sake add to my already innumerable
obligations, by praying for a poor unfruitful and ungrateful dwarf. I
am sick of my vileness, and yet just comes in a letter acquainting
me, that my preaching hath been blessed to many this morning.
Good God, what is this? Grace! Grace! I am lost, I am lost.

Take me Uriel, take me hence,

And bear my soul to God.

Your Ladyship sees I am running into my old fault. I cannot well help
it, when writing to your Ladyship. May the choicest of God’s mercies
rest on you and yours! I hope my poor but sincere respects will find
acceptance with Lady S――’s, Master H――, &c. I must away to pray
for your Ladyship and them, and therefore hasten to subscribe
myself, ever-honoured Madam,

Your Ladyship’s most ready servant,

G. W.

♦ “Donington” replaced with “Donnington”

LETTER MCIII.
To Mr. D―― B――.

Newcastle, October 4, 1755.

My dear Friend,

W HO would but wish to be in heaven, where we shall enjoy the


communion of saints without interruption? Whilst here, how
long is it before we can answer each other’s letters? With difficulty I
now sit down to answer your last; for these seven or eight days
past, I have been deeply engaged in travelling, and preaching thrice
a day. Jesus Christ hath made it pleasant to my soul, and comfortably
supported my weak body. It being so late in the year, I cannot
proceed further northward. However I must write, if it be only to let
you know, that my dear Scotch friends are continually upon my
heart, and that I most earnestly beg the continuance of their
prayers. I am a dwarf,—I am a dwarf,—and that is enough to excite
their pity. Alas! alas! Autumn is come, winter is drawing on, and (O
my God) how little have I done for thee in the summer. The concern
I feel upon this account almost prevents my writing. Adieu, I must
retire.—My tender love to Mrs. B――, and all that are so kind as to
inquire after me. Exhort them to love, and live near to the ever-
loving Jesus, and for his great name’s sake, never to forget, my dear
friend,

Their and your affectionate friend, and ready servant for


Christ’s sake,

G. W.

LETTER MCIV.
To Mr. ――.
London, October 31, 1755.

My very dear Friend,

L AST night, a never-failing God brought me from the north of


England, where I have been enabled to preach twice and thrice
a day, to many, many thousands for these two months last past. And
yet I cannot die.—Nay they tell me, “I grow fat.” O that I may grow
in grace, especially in humility! Then would the Lord delight to
honour me. Vile as I am, this he continues to do. Never did I see the
word more blessed, or so many thousands run after it with greater
greediness. Next to inviting them to Christ, I have always taken care
to exhort them to pray for King George, and our dear friends in
America. I trust, that thousands are now engaged this way, and
whatever dark providences may intervene, I hope to hear they have
been more than conquerors.—“Pray continue to write,” I often tell
my friend. I often think of him who sent me the glass, before the
friend of sinners. God almighty bless you and yours, and all enquiring
dear souls, with all spiritual and temporal blessings! I see some are
marrying, and others giving in marriage. May the Lord Jesus sanctify
every change, till we all come to sit down at the marriage feast of
the supper of the Lamb! There I hope ere long to meet you. Fly, fly,
Time: hasten, hasten, O wished-for Eternity! Adieu: my tender love
to all. I wish dear Mr. T―― a good help-mate, but above all, I wish
him much success in espousing poor sinners to the ever adorable
Jesus. Once more farewel.

Yours, &c.

G. W.

LETTER MCV.
To Mr. B――.

London, November 1, 1755.

My dear Mr. B――,

O N Thursday evening, a never-failing Providence brought me in


safety from my northern circuit, and this morning I find a letter
of a distant date from you, which before I look over my other letters,
I sit down to answer. And what shall I say? Blessed be God, I have
good news to send you from the north country; never did I see the
word of God have freer course, or congregations more numerous or
attentive. I was strengthened to preach generally twice or thrice a
day, and thanks be to my gracious Master, my poor carcase held it
out. Next to Jesus, my King and country were upon my heart. I acted
as at Stroud, and other parts of Gloucestershire, and I hope I shall
always think it my bounden duty, next to inviting sinners to the
blessed Jesus, to exhort my hearers to exert themselves against the
first approaches of popish tyranny and arbitrary power. O that we
may be enabled to watch and pray against all the opposition of
Antichrist in our hearts; for after all, there lies the most dangerous
man of sin; there is the temple in which he sits, exalting himself
above all that is called God. And what shall, what can destroy him?
Nothing but the breath of the Redeemer’s mouth, and the brightness
of his appearing, by his blessed spirit in our souls. O for more of this
baptismal fire! God give you, and the dear Alderman, to pray
earnestly for me, that I may begin at length to be a little alive to my
God. O winter! winter! how near art thou drawing, and how little
have I done for Jesus in the summer! Perhaps before Christmas I
may see you again. Future things belong to Jesus. To his tender
never-failing mercy do I most heartily commit you, and the dear
Alderman, all your relations, and all enquiring friends, and once
more beg that you will not forget to pray for, my dear Mr. B――,

Yours most affectionately in our common Lord,


G. W.

LETTER MCVI.
To Lady H――n.

London, November 1, 1755.

Ever-honoured Madam,

W HAT shall I say? Indeed and indeed, it hath given me great


concern, that I could not perform my promise to return to
Donnington-park so soon as I expected.—But had I done so, I must
have failed preaching at least to above fifty thousand souls, who at
different places ran most greedily many miles after the everlasting
gospel. This I thought your Ladyship would by no means approve of,
and therefore acquiesced. On Thursday evening, with no small
regret I came to town, after having preached about a hundred
times, and travelled about eight hundred miles in the country.
Blessed be God, my feeble carcase was strengthened to hold out,
though for more than ten days together, I preached thrice a day.—O
that I could preach three hundred times! all would be little enough,
(alas, alas, infinitely too little) to testify my feeble love to the ever-
loving, ever-lovely Jesus. I hope that your Ladyship, and the other
elect Ladies, will enjoy much of his blessed spirit, in your present
sweet retreat. After about a week’s stay here, I hope to move
westward. O winter, winter! haste and fly, that I may again set out,
and begin to spring for my God! I know I shall have your Ladyship’s
prayers, and I am sure your Ladyship and family and friends have
mine. Yesterday I waited upon the Countess D――, and on
Thursday, God willing, I am to dine with her Ladyship. Blessed be
God, all was well. O for growth in grace! O for the total destruction
of self and selfishness! Alas, what inward purgations and
martyrdoms must be undergone! Lord Jesus, we are the clay, and
thou art the potter; stamp thine image in what way thou pleasest! I
know your Ladyship will say, Amen. I trust an “Even so, Lord Jesus,
come quickly,” is sincerely added by, ever-honoured Madam,

Your Ladyship’s most dutiful, obliged, and ready servant, for


Christ’s sake,

G. W.

LETTER MCVII.
To the Honourable J―― R――.

London, Numbers 7, 1755.

Very dear Sir,

A RE you yet called out in defence of your country? The measures


taken by your honourable and loyal council and assembly, I
hope will be blessed to prevent a stir so near to Boston. I am glad to
hear, that the Ladies are employed in making the soldiers cloaths; I
trust my female friends are some of the most active. Surely, the
cause is the cause of God, and if done out of love to Jesus, this
labour of love shall not go unrewarded. God make male and female
good soldiers of Jesus Christ! Nothing like fighting under his banner;
he is a refuge from every storm. I can only add, that I most
earnestly commend you and yours, and the whole circle of my never
to be forgotten friends, to his never-failing mercy, and intreat you to
accept these few hasty lines, as a token of love and respect
unfeigned, from, very dear Sir,

Yours most affectionately in our common Lord,


G. W.

LETTER MCVIII.
To the Honourable A―― O――.

London, November 8, 1755.

Very dear Sir,

I HEAR you have been sitting night and day in council. May Jesus,
the wonderful counsellor, preside in your assembly, and influence
you to pursue such measures, as may be blessed to the humbling a
persidious enemy, and making the dear New Englanders more than
conquerors through the love of God! All we can do on this side the
water, is to pray. This I trust thousands are doing every day.—I
seldom preach, without mentioning dear New England. O for more
good news from that part of yonder new world! O that this time of
outward danger, may be sanctified to the exciting of greater zeal
against our inward spiritual enemies! For after all, the man of sin in
our own hearts, is the greatest foe the real christian hath to fear.
May Jesus destroy him both within and without, by the breath of his
mouth, and the brightness of his appearing! Blessed be God, the
prospect is promising here! In the north of England, the word runs
and is glorified more than ever, and in London people flock like
doves to the windows:—and yet I feel a strong attraction for
America. Pray be so kind, very dear Sir, to send me some account
now and then, how matters stand.—Perhaps it may be of some
service. I could enlarge, but must drop a line or two more to some
more friends, and therefore can only send my most cordial
salutations to yourself, and whole houshold, and begging a
continued interest in your prayers, subscribe myself, very dear Sir,
Your most obliged, affectionate friend, and ready servant
for Christ’s sake,

G. W.

LETTER MCIX.
To Lady H――n.

London, November 10, 1755.

Ever-honoured Madam,

Y OUR Ladyship’s kind and condescending letter, found me just


returned from Chatham, and led me (as your Ladyship’s letters
always do) to a throne of grace. I immediately threw myself
prostrate before God, and earnestly prayed, in my poor feeble
manner, that grace, mercy, and peace might be multiplied upon your
Ladyship, and your happy family. The Court, in the best sense of the
word, is now removed to Clifton. For there only is the real court
kept, where Jesus reigns, and where he has erected a spiritual
kingdom in the heart. All besides this, is only tinsel and glitter. Here
alone is real and abiding happiness to be found. O for further
searches into the heighths and depths of God? O for further leadings
into the chambers of that selfish, sensual, and devilish imagery, that
yet lie latent in my partly renewed heart. This self-love, what a
Proteus! This self-will, what an Hydra? This remaining body of sin
and death, what an antichrist! what a scarlet whore! what a hell!
what a red dragon! what a cursed monster is it! How hard, how slow
he dies! O what gratitude do I owe to the bruiser of this serpent’s
head! O for a heart gladly to embrace every cross, every trying
dispensation, that may have a tendency to poison, or starve, or nip
the buddings of the old, and cherish, promote, or cause to bloom
and blossom the graces and tempers of the new man in my soul!
Ordinances, providences, doctrines, (I am more and more
convinced) are of no service to believers, than as they are attended
with this mortifying and life-giving power. Happy family, that have
this one thing in view! Happy retirement, that is improved to this
blessed purpose! Happy, therefore, good Lady H――n, and the other
elect Ladies, who are determined thus to go on hand in hand to
heaven! All hail, ye new-born, heaven-born souls! ye know, by happy
experience, that Jesus is an inward as well as an outward saviour,
and that he came indeed and indeed to redeem us from this present
evil world. Was even annihilation to follow at death, who would but
have this redemption whilst they live? But, glory, glory be to God, it
is only the dawning of an eternal day, the beginning of a life that is
ere long to be absorbed and swallowed up in never-ceasing,
uninterrupted fruition of the ever-blessed triune Deity. O the depth,
the height of this love of God! It passeth human and angelic
knowledge. My paper only permits me to add, (God knows it is with
gratitude and sincerity) that I am, ever-honoured Madam,

Your Ladyship’s most dutiful and ready servant,

G. W.

LETTER MCX.
To Mr. S――.

Bristol, November 30, 1755.

My very dear Sir,

T O be three weeks without sending you a line, seems a long while


to me. What if we should meet ere long in an endless and
happy eternity? For near ten days past I have preached in pain,
occasioned by a sore throat, which I find now is the beginning of an
inflammatory quinsey. Silence and warmth, the doctor tells me,
under God, may cure me, but heaven (if I had my will) is my choice,
especially if I can speak no longer on earth for my God. However,
painful and expensive as, in a spiritual sense, the medicine of silence
is, I have promised to be very obedient, and therefore I have not
preached this morning. If I grow better, (as the world terms it) I
hope to see you in about a fortnight, if otherwise, God willing, you
shall hear from me again. Blessed be Jesus, I am ready; I know that
my Redeemer liveth. O that all who were lately swallowed up in
Portugal, had known it! Then an earthquake would only be a
rumbling chariot to carry the soul to God. Poor Lisbon! how soon are
all thy riches and superstitious pageantry swallowed up! What a
shock must the news give to a full exchange! Who would but lay up
treasure in heaven? Thanks be to God, for teaching you, my very
dear Sir, this heavenly art! May you and yours improve in it every
day and hour. This is my comfort, all my goods are gone before me.
O the pleasure of having nothing, and yet possessing all things in
Jesus! This be my happy lot! I beg a continued interest in your
prayers, and trust that living and dying you will always be
remembered by, my very dear friend,

Your most affectionate friend and ready servant for Christ’s


sake,

G. W.

LETTER MCXI.
To the Reverend Mr. H―― D――.

Bristol, Dec. 6, 1755.


My dear Friend and Brother,

O NE would think, that Providence did in a more immediate


manner interpose to prevent our meeting. I saw your last to
Mr. M――n, and intended to have answered it for him, but it hath
pleased a gracious and sovereign God to silence me for a few days,
by a sore throat, which was like to have terminated in an
inflammatory quinsey. This gave me hopes of putting into port; but it
seems I am yet to put out to sea again. O that my stammering
tongue may be loosed, and that I may begin to begin to speak in
earnest for my God! Every thing, both from within and without, calls
upon us to cry aloud and spare not. Whatever becomes of ill and
hell-deserving me, may the ever-loving and ever-lovely Jesus cause
your bow to abide in strength! I trust many arrows have stuck fast in
the North of England; and in the West, I trust, the sword of the Lord
hath not returned empty. On Monday se’nnight, God willing, I
purpose going to Gloucester, and hope to be in London soon. Our
meeting, therefore, must necessarily be put off till Spring. In the
meanwhile, I should be glad to see and converse with Mr. J――, of
whom I have heard a good report. I am sorry there is no greater
connection between England and Wales. The harvest is great, and
the disinterested labourers are few. This is my comfort, the Lord of
the harvest can and will, in his own time and way, thrust out more
labourers into the harvest. That he may own and bless you, and all
in your connection, more and more, is the earnest prayer of, my very
dear friend,

Yours most affectionately in our glorious Head,

G. W.

LETTER MCXII.
To Lady H――n.

London, December 31, 1755.

Ever-honoured Madam,

Y OUR Ladyship’s kind and condescending letter should not have


lain so long by me, had not bodily weakness, and my Christmas
labours, prevented my writing. Indeed and indeed my good Lady, it
hath been a joyful mournful season to my inward man. For exclusive
of a pretty sharp outward trial, Saturday last being my birth-day, my
soul was deeply exercised from morning till evening, in thinking how
much in one-and-forty years I have sinned against, and how little I
have done for an infinitely good and ever-blessed God. This
impression yet lies deep upon my heart, and therefore, through
divine assistance, I purpose to end the old year in preaching on
those words, “I abhor myself, and repent in dust and ashes.” O that
all things belonging to the old man, may die in me, and all things
belonging to the new man live and grow in me! But alas, this is a
work of time. Every day and every hour must we be passing from
death to life. Mortification and vivification make up the whole of the
divine work in the new-born soul. Come, Lord Jesus, come quickly;
have compassion on this barren fig-tree, and if it is to be spared
another year, so dig and dung round it, that it may bring forth much
fruit unto God! But shall I conceal the goodness of my long-suffering
Master? No: I dare not;—for in spite of my unworthiness, he still
continues to smile upon my poor ministrations, and gives me to see
his stately steps in the great congregations. A noble chapel is now
opened in Long-acre, where I am to read prayers and preach twice a
week. Hundreds went away last night, who could not come in; but
those that could, I trust, met with Jesus. Mr. C―― and I have met
twice, and hope for a third interview very soon. Lord Jesus, make me
a peace-maker! I am obliged to Mrs. W―― and the other Ladies for
their kind remembrance of an unworthy worm. I return it, by
earnestly praying, that they and your Ladyship may be filled with all
the fulness of God. I can rise no higher, and therefore, with all
possible acknowledgments for all unmerited favours, I must hasten
to subscribe myself, ever-honoured Madam,

Your Ladyship’s most dutiful, obliged, and very ready


servant for Christ’s sake,

G. W.

LETTER MCXIII.
To Mr. S――.

London, January 1, 1756.

My very dear Friend,

Y OUR not answering my two last sooner, gave me pain; sorrows


are lessened, and joys become greater by being communicated.
It is so with an earthly friend, much more so with the friend of
sinners.

Our sorrows and our tears we pour,

Into the bosom of our God.

He bottles them all up, and will not suffer one of them to fall to the
ground unregarded. I hope that these trials, which, like Job’s
messengers, come one upon the back of another, by being
sanctified, will make your soul as a watered garden. You know who
hath said, “They that sow in tears, shall reap in joy.” O blessed
religion, that shews us the holy art of gaining by our losses, and
rising by our falls! Was it in my power, this letter should enclose
something that would stop every temporal gap; but I am not rich at
present. Poor, yet endeavouring to make many rich, I would have my
motto still! Thanks be to God, at our lowest estate we can draw on
the bank of heaven. A believer never hath a bill protested there. “My
God (says the Apostle Paul) shall supply all your need according to
his riches in Christ Jesus.” Away, and endorse it afresh, and send it
directly away post on the wings of prayer. Never fear any trial that
sends you to your knees; You must then needs go forward whether
you know it or not. I would enlarge, but weakness prevents. I have
been in the furnace; I hope it is intended to prepare me for fresh
success. The awakening at London seems to be quite new. Adieu,
adieu. I am called away.

Ever yours, &c.

G. W.

LETTER MCXIV.
To the Reverend Mr. G――.

London, January 22, 1756.

Reverend and very dear Sir,

E NCLOSED you have some extracts, which perhaps may afford


you comfort, and I trust will excite you to pray for one, who is
indeed less than the least of all saints. Ever since I came from the
North, it hath pleased a sovereign Lord to visit me with a violent cold
and sore throat, which threatened an inflammatory quinsey. Such a
thing, I hoped, would have soon carried me, where this cold heart
should for ever be inflamed with seraphic love. But alas! I fear this
wish’d-for time is not at hand. One physician prescribed a perpetual
blister, but I have found perpetual preaching to be a better remedy.
When this grand catholicon fails, it is over with me. You will pray,
that (if I must put out to sea again) it may be to take some fresh
prizes for my God. Every day brings us fresh news of newly
awakened souls. Both at this and the other end of the town, (where
I now preach at a chapel twice a week) there is a glorious stirring
amongst the dry bones. My heart is pained for dear America; but I
trust the Lord will fight their battles, and make them more than
conquerors. Happy they who have fled to Jesus: he is a strong and
sure refuge from every storm. I hope he hath appeared for his cause
at Glasgow. May that dear people never be left without many
teaching priests! I send my kind host and hostess, and all enquiring
friends, most cordial respects, and beg you to accept the same from,
my very dear Sir,

Yours most affectionately in our common Lord,

G. W.
LETTER MCXV.
To Lady H――n.

London, January 29, 1756.

Ever-honoured Madam,

Y OUR Ladyship will see by the inclosed, how dangerous it is to


give me liberty. I would not grow upon it, and yet I cannot
discharge my conscience, unless I lay particular distressing
applications before your Ladyship. I know the person mentioned in
Mr. G――’s letter, and believe he belongs to the little flock of Jesus:
the best recommendation that can be laid before your Ladyship. I
doubt not but what your Ladyship hath done in behalf of the
prisoner, will have good effect: I do not know how soon I may be
called before my superiors myself. The sons of Tubal and Cain
continue to serenade me at Long-Acre chapel. They have been
called before a justice; and yesterday the Bishop of B―― sent for
them, and enquired where I lived. My house is pretty public, and the
Bishop of souls shall answer for me:—he does. One, who subscribes
to hire men to make the noise, hath been pricked to the heart, and
can have no rest till he speaks with me. Thus Jesus gets himself the
victory.――One of the inclosed extracts comes from a person, that a
few weeks ago was a confirmed deist: now, I trust, he is a little
child. The Redeemer speaks, and it is done; he commands, and new
creatures instantaneously arise before him. Your Ladyship enjoined
me to be particular; I could be more so, but must send a few lines to
the elect Ladies. That they may find both them and your Ladyship
filled with all the fulness of God, is the earnest prayer of, ever-
honoured Madam,
Your Ladyship’s most dutiful, obliged, and very ready
servant for Christ’s sake,

G. W.

LETTER MCXVI.
To Mr. F――.

January 30 1756.

Honoured Sir,

G RATITUDE constrains me to send you a few lines of thanks for


the care and zeal you have expressed in suppressing the late
disorders at Long-Acre chapel. A better acknowledgment will, I trust,
await you at his bar, by whom kings reign, and princes decree
justice, and who hath instituted magistracy to be a terror to evil
doers, and a praise to them that do well. I hear that some unhappy
man hath incurred the penalty inflicted by our salutary laws. As
peace, not revenge, is the thing aimed at, I should rejoice if this
could be procured without the delinquents suffering any further
punishment. Perhaps what hath been done already, may be
sufficient to deter others from any further illegal proceedings, and
that will be satisfaction enough, honoured Sir, to

Your much obliged humble servant,

G. W.

LETTER MCXVII.
To the Bishop of B――.

Tabernacle-House, February 2, 1756.

My Lord,

A FEW weeks ago, several serious persons chosen to be a


committee for one Mr. B――, applied to me in the name of Jesus
Christ, and a multitude of souls desirous of hearing the gospel, to
preach at a place commonly called Long-Acre chapel. At the same
time they acquainted me, “That the place was licensed; that Mr.
B―― either had taken, or was to take it for a certain term of years,
and had preached in it for a considerable time, as a protestant
Dissenting minister: notwithstanding, (they added) I might use the
Liturgy if I thought proper, so that I would but come and preach
once or twice a week.” Looking upon this as a providential call, from
him, who in the days of his flesh taught all that were willing to hear,
on a mount, in a ship, or by the sea-side, and who after his
ascension, commanded us by his Apostle, to be “instant in season
and out of season,” I readily complied, and humbly hope that my
feeble, though I trust sincere labours, have not been altogether in
vain in the Lord. This being the case, your Lordship will necessarily
suppose, that I was somewhat surprized at the prohibition I received
from your Lordship this evening. For I looked upon the place as a
particular person’s property, and being, as I was informed, not only
unconsecrated, but also licensed according to law, I thought I might
innocently preach the love of a crucified Redeemer, and for his great
name’s sake, loyalty to the best of princes our dread sovereign King
George, without giving any just offence to Jew or Gentile, much less
to any bishop or overseer of the church of God. As I have therefore
given notice of preaching to-morrow evening, and every Tuesday
and Thursday whilst I am in town, I hope your Lordship will not look
upon it as contumacy, or done out of contempt, if I persist in
prosecuting my design, till I am more particularly apprized wherein I
have erred. Controversy, my Lord, is what I abhor, and as raising
popular clamours, and ecclesiastical dissentions must be quite
unseasonable, especially at this juncture, when France and Rome
and hell ought to be the common butt of our resentment, I hope
your Lordship will be so good as to inform yourself and me more
particularly about this matter; and upon due conviction, as I have no
design but to do good to precious souls, I promise to submit. But if
your Lordship should judge it best to decline this method, and I
should be called to answer for my conduct, either before a spiritual
court, or from the press, I trust the irregularity I am charged with,
will appear justifiable to every true lover of English liberty, and what
is all to me, will be approved of at the awful and impartial tribunal of
the great Shepherd and Bishop of souls, in obedience to whom I beg
leave to subscribe myself, my Lord,

Your Lordship’s most dutiful son and servant,

G. W.

LETTER MCXVIII.
To Mr. B――.

Tabernacle-House, February 9, 1756.

Reverend Sir,

O N our late fast day, a collection was made at the Tabernacle


where I preach, eighty pounds of which I have deposited in
the hands of Mr. A――, in Fleet-street, for the use of the poor
persecuted French protestants. That our great and compassionate
High-priest may accept it as done to himself, and bless you and the
honourable society established for promoting so laudable a charity, is
the hearty prayer of, reverend Sir,
Your unworthy brother and fellow-labourer in the cause of
our common Lord,

G. W.

LETTER MCXIX.
To the Bishop of B――.

Tabernacle-House, February 16, 1756.

My Lord,

I THIS evening received your Lordship’s kind letter, and though it is


late, and nature calls for rest, yet in the fear of him to whom all
hearts are open, all desires known, and from whom no secrets are
hid, I desire now to sit down and give your Lordship an explicit
answer. God, even that God by whom I am to be judged, can
witness, that with a disinterested view to promote his glory, and the
welfare of precious and immortal souls, I entered into holy orders,
according to the form of ordination of the church of England; and, as
thousands can testify, for near these twenty years last past, I have
conscientiously defended her homilies and articles, and upon all
occasions spoken well of her liturgy. Either of these, together with
her discipline, I am so far from renouncing, much less from throwing
aside all regard to, that I earnestly pray for the due restoration of
the one, and daily lament the wanton departure of too, too many
from the other. But, my Lord, what can I do? When I acted in the
most regular manner, and when I was bringing multitudes even of
Dissenters themselves to croud the churches, without any other
reason being given than that too many followed after me, I was
denied the use of them. Being thus excluded, and many thousands
of ignorant souls, that perhaps would neither go to church nor
meeting-houses, being very hungry after the gospel, I thought
myself bound in duty to deal out to them the bread of life. Being
further ambitious to serve my God, my King, and my country, I
sacrificed my affections, and left my native soil, in order to begin
and carry on an Orphan-house in the infant colony of Georgia,
which, through the divine blessing, is put upon a good foundation.
This served as an introduction, though without design, to my visiting
the other parts of his Majesty’s dominions in North-America; and I
humbly hope, that many made truly serious in that foreign clime, will
be my joy and crown of rejoicing in the day of the Lord Jesus. If it
was not for this hope, nay, my Lord, if I was not assured, that the
blessed Redeemer (O amazing condescension) hath vouchsafed to
own me for the real conversion, and turning of many from darkness
to light, the weakness of my frequently worn out and decaying body,
the innumerable temptations that have beset my soul, together with
the violent opposition I have met with from various quarters, would
long since have quite overwhelmed, and at least have prevailed on
me to accept some of those offers that have been made me to
nestle, by accepting of which I might have screened myself from
that obloquy and contempt, which, in some degree or other, every
day I have the honour to meet with for Jesu’s sake. But hitherto
having obtained help from God, without eating a morsel of the
church of England’s bread, I still continue to use her liturgy,
wherever a church or chapel is allowed me, and preach up her
articles, and enforce her homilies. Your Lordship therefore judgeth
exceeding right, when you say, “I presume you do not mean to
declare any dissent from the church of England.”—Far be it from me;
no, my Lord, unless thrust out, I shall never leave her, and even
then (as I hope whenever it happens it will be an unjust extrusion) I
shall still continue to adhere to her doctrines, and pray for the much
wished-for restoration of her discipline, even to my dying day. Fond
of displaying her truly protestant and orthodox principles, especially
when church and state are in danger from a cruel and popish
enemy, I am glad, my Lord, of an opportunity of preaching, though it
should be in a meeting-house; and I think it discovers a good and
moderate spirit in the Dissenters, who will quietly attend on the
church service, as many have done, and continue to do at Long-Acre
chapel, while many, who I suppose stile themselves her faithful sons,
by very improper instruments of reformation, have endeavoured to
disturb and molest us. If the lessor of this chapel, my Lord, hath no
power to let it out, or if it be not legally and properly licensed, I
have been deceived indeed; and if upon enquiry I find this to be the
case, I shall soon declare in the most public manner, how both your
Lordship and myself have been imposed upon. But if it appears, that
the lessor hath a right to dispose of his own property, and that the
place is licensed, if not in the court books of the Quarter Sessions,
yet in the Commons or some other proper court; and as some good,
I trust, has been, and hope will yet be done by this foolishness of
preaching, surely your Lordship’s candour will overlook a little
irregularity; since I fear that in these dregs of time, these last days,
wherein we live, we must be obliged to be irregular, or in short we
must do no good at all. My Lord, I remember well, (and O that I
may more than ever obey your Lordship’s admonition) and often
recollect that awful day wherein I was ordained priest, and when
authority was given me, by my honoured friend and father good
Bishop Benson, to preach the word of God. O that the glorious
exhortation, which he delivered with so much solemnity, may be
written upon the tables of my heart! Mindful of this, I shall be always
ready to go out, and seek for Christ’s sheep that are dispersed
abroad, and be willing to spend and be spent for the good of his
children which are in the midst of this naughty world. Never did I so
much as dream, my Lord, that this was only a local commission, or
that the condition annexed, “Where you shall be lawfully appointed
thereunto,” was to confine me to any particular place, and that it
would be unlawful for me to preach out of it. It is plain my Lord
Bishop of Gloucester did not think so; for when his secretary brought
a licence for me, his Lordship said, “It would cost me thirty shillings,
and therefore I should not have it.” And when after being presented
to the late Bishop of London, I applied to him for a licence, his
lordship was pleased to say, “I was going to Georgia, and needed
none.” Accordingly I preached in most of the London churches under
his Lordship’s immediate inspection; and why any other licence than
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like