100% found this document useful (1 vote)
21 views

Python for Teenagers: Learn to Program Like a Superhero! James R Payne instant download

Ebook access

Uploaded by

eminajenae3r
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
21 views

Python for Teenagers: Learn to Program Like a Superhero! James R Payne instant download

Ebook access

Uploaded by

eminajenae3r
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/ 57

Python for Teenagers: Learn to Program Like a

Superhero! James R Payne download

https://textbookfull.com/product/python-for-teenagers-learn-to-
program-like-a-superhero-james-r-payne/

Download more ebook from https://textbookfull.com


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

Python for Teenagers: Learn to Program like a


Superhero! 2nd Edition Payne

https://textbookfull.com/product/python-for-teenagers-learn-to-
program-like-a-superhero-2nd-edition-payne/

Learn to Program with Python 3: A Step-by-Step Guide to


Programming Irv Kalb

https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-irv-kalb/

Learn to Program with Python 3: A Step-by-Step Guide to


Programming, 2nd Edition Irv Kalb

https://textbookfull.com/product/learn-to-program-with-
python-3-a-step-by-step-guide-to-programming-2nd-edition-irv-
kalb/

Learn Raspberry Pi Programming with Python: Learn to


Program on the World's Most Popular Tiny Computer Donat

https://textbookfull.com/product/learn-raspberry-pi-programming-
with-python-learn-to-program-on-the-worlds-most-popular-tiny-
computer-donat/
Learn Raspberry Pi Programming with Python: Learn to
Program on the World’s Most Popular Tiny Computer, 2nd
Edition Wolfram Donat

https://textbookfull.com/product/learn-raspberry-pi-programming-
with-python-learn-to-program-on-the-worlds-most-popular-tiny-
computer-2nd-edition-wolfram-donat/

A Tour Of Data Science: Learn R And Python In Parallel


Nailong Zhang

https://textbookfull.com/product/a-tour-of-data-science-learn-r-
and-python-in-parallel-nailong-zhang/

Teach Your Kids to Code A Parent Friendly Guide to


Python Programming 1st Edition Bryson Payne

https://textbookfull.com/product/teach-your-kids-to-code-a-
parent-friendly-guide-to-python-programming-1st-edition-bryson-
payne/

PHP and Algorithmic Thinking for the Complete Beginner


2nd Edition Learn to Think Like a Programmer Bouras

https://textbookfull.com/product/php-and-algorithmic-thinking-
for-the-complete-beginner-2nd-edition-learn-to-think-like-a-
programmer-bouras/

Python One Liners Write Concise Eloquent Python Like a


Professional 1st Edition Christian Mayer

https://textbookfull.com/product/python-one-liners-write-concise-
eloquent-python-like-a-professional-1st-edition-christian-mayer/
Python
for Teenagers
Learn to Program like a Superhero!

James R. Payne
Python for Teenagers
Learn to Program like a Superhero!

James R. Payne
Python for Teenagers: Learn to Program like a Superhero!
James R. Payne
Deerfield Beach, FL, USA

ISBN-13 (pbk): 978-1-4842-4549-1    ISBN-13 (electronic): 978-1-4842-4550-7


https://doi.org/10.1007/978-1-4842-4550-7

Copyright © 2019 by James R. Payne


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Todd Green
Development Editor: James Markham
Coordinating Editor: Jill Balzano
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-4549-1. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To my wife Whitney Payne, for always believing and pretending not to
notice when I yell at the computer.
To my parents, Ronnie and Sharon Payne, and my brother, also Ronnie
Payne, who all mysteriously have “ron” in their name and who always
told me I could become whatever I wanted in life, even when I told
them I wanted to be Batman.
To Dorjan Williams, who, years ago, helped me create a universe of
ridiculous comic book characters. To Eric Miller, who helps me solve
problems big and small, including slaying a dragon in my backyard, so
that I can focus – sometimes – on getting work done. Nicholas Rini
introduced me to both programming and comic books, and without
him, this book would not exist. Nanci Packard and Wendy White
provided inspiration with their use of words so big they couldn’t
possible fit in a book. Thanks to members of the old Dev Shed crew:
Jennifer Ruggieri – who got me the job that got me the book – Charles
Fagundes, and Keith Lee, for coding help and reminding me
(frequently) that my cup overfloweth. Jose Escalante, I thank you here
because you were the only one that could see John Cena. Enrique
Stone… you know what you did.
A special thanks to Sophie “the Bulldog” Payne for letting me use her
likeness in this book and always being such a good helper in the
kitchen.
I would be remiss if I failed to thank the mad titan, Thanos, who helped
me accomplish so much with just a snap of his fingers. Mister T pitied
this fool, while Richard C. helped me “hit em with the hein.” And lastly,
thank you to a handful of the writers that inspire me: A. Lee Martinez,
Neil Gaiman, Frank Miller, Alan Moore, Jim Starlin, and Stephen
King – can’t you guys write any faster?
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewer���������������������������������������������������������������������������������xv


Acknowledgments�������������������������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Chapter 1: Introduction to Computer Programming and Python������������������������������ 1


Programming Language Overview������������������������������������������������������������������������������������������������ 2
Python Overview��������������������������������������������������������������������������������������������������������������������������� 2
How Does Python Differ from Other Programming Languages?��������������������������������������������������� 3
The Benefits of Python������������������������������������������������������������������������������������������������������������������ 3
Examples of Python in the Wild����������������������������������������������������������������������������������������������������� 5
Your First Python Program������������������������������������������������������������������������������������������������������������ 6
Installing Python��������������������������������������������������������������������������������������������������������������������������� 7
Installing Python on Windows�������������������������������������������������������������������������������������������������� 7
Installing Python on Other Operating Systems��������������������������������������������������������������������������� 15
In This Episode!��������������������������������������������������������������������������������������������������������������������������� 16

Chapter 2: It All Adds Up���������������������������������������������������������������������������������������� 17


Operator Precedence������������������������������������������������������������������������������������������������������������������ 18
Data Types: Know Your Enemy���������������������������������������������������������������������������������������������������� 22
Converting Number Data Types��������������������������������������������������������������������������������������������������� 25
What Are Variables?�������������������������������������������������������������������������������������������������������������������� 26
Super Hero Generator 3000�������������������������������������������������������������������������������������������������������� 29
In This Episode!��������������������������������������������������������������������������������������������������������������������������� 33

v
Table of Contents

Chapter 3: String Things Along������������������������������������������������������������������������������� 37


Leave Your Comments at the Door���������������������������������������������������������������������������������������������� 37
Block Commenting���������������������������������������������������������������������������������������������������������������� 39
Inline Commenting���������������������������������������������������������������������������������������������������������������� 40
Other Uses for Commenting�������������������������������������������������������������������������������������������������� 40
Texting – Without Your Phone����������������������������������������������������������������������������������������������������� 41
Working with Strings and Variables��������������������������������������������������������������������������������������� 43
Longer Strings����������������������������������������������������������������������������������������������������������������������� 45
Strings on Multiple Lines������������������������������������������������������������������������������������������������������� 46
Formatting Strings����������������������������������������������������������������������������������������������������������������� 46
Introducing a New Weapon to Your Arsenal: Lists����������������������������������������������������������������� 49
Changing Lists����������������������������������������������������������������������������������������������������������������������� 52
Other List Methods���������������������������������������������������������������������������������������������������������������� 54
In This Episode!��������������������������������������������������������������������������������������������������������������������� 56

Chapter 4: Making Decisions���������������������������������������������������������������������������������� 59


Making Decisions������������������������������������������������������������������������������������������������������������������������ 60
Conditional Statements��������������������������������������������������������������������������������������������������������������� 61
Behold – The If Statement!���������������������������������������������������������������������������������������������������� 62
Boolean Logic and Comparison Operators���������������������������������������������������������������������������� 65
Else Statements�������������������������������������������������������������������������������������������������������������������� 67
Else If Statements����������������������������������������������������������������������������������������������������������������� 69
Logical Operators������������������������������������������������������������������������������������������������������������������ 72
Nesting – Not Just for the Birds�������������������������������������������������������������������������������������������� 75
In This Episode!��������������������������������������������������������������������������������������������������������������������� 78

Chapter 5: Loops and Logic������������������������������������������������������������������������������������ 81


What Are Loops?������������������������������������������������������������������������������������������������������������������������� 81
Limiting Loops����������������������������������������������������������������������������������������������������������������������� 86
For Loops������������������������������������������������������������������������������������������������������������������������������� 87
More Fun with For Loops������������������������������������������������������������������������������������������������������� 91
Break, Continue, and Pass Statements���������������������������������������������������������������������������������� 93
In This Episode!��������������������������������������������������������������������������������������������������������������������� 96

vi
Table of Contents

Chapter 6: Using What We’ve Learned�������������������������������������������������������������������� 99


Creating Your First Real Program������������������������������������������������������������������������������������������������ 99
Importing Modules�������������������������������������������������������������������������������������������������������������� 100
Creating Our Variables��������������������������������������������������������������������������������������������������������� 101
Defining Our Lists���������������������������������������������������������������������������������������������������������������� 101
Introductory Text and Accepting Input from the User���������������������������������������������������������� 102
Creating Suspense!������������������������������������������������������������������������������������������������������������� 103
Randomizing Super Hero Names����������������������������������������������������������������������������������������� 105
A Quick Check-in����������������������������������������������������������������������������������������������������������������� 107
Randomizing the Super Powers������������������������������������������������������������������������������������������ 109
Finishing Our Program��������������������������������������������������������������������������������������������������������� 112
The superHeroGenerator3000 Code – Completed!�������������������������������������������������������������� 115

Chapter 7: Saving Time with Functions, Modules, and Built-ins�������������������������� 121


Defining Modules���������������������������������������������������������������������������������������������������������������������� 122
Built-ins������������������������������������������������������������������������������������������������������������������������������� 122
Packages����������������������������������������������������������������������������������������������������������������������������� 126
Creating Your Own Module�������������������������������������������������������������������������������������������������� 128
Common Built-in Functions������������������������������������������������������������������������������������������������������ 131
String Functions������������������������������������������������������������������������������������������������������������������ 131
Practice Your New Functions���������������������������������������������������������������������������������������������������� 137
String Function Examples���������������������������������������������������������������������������������������������������� 137
Number Function Examples������������������������������������������������������������������������������������������������ 138
In This Episode!������������������������������������������������������������������������������������������������������������������������� 139

Chapter 8: Using Classes and Objects������������������������������������������������������������������ 141


What Is OOP?���������������������������������������������������������������������������������������������������������������������������� 141
What Are Classes (And Will I Be Graded?)��������������������������������������������������������������������������� 142
What Are Objects����������������������������������������������������������������������������������������������������������������� 143
Creating Our First Class������������������������������������������������������������������������������������������������������� 143
Creating Our First Object����������������������������������������������������������������������������������������������������� 145
Improving the Super Hero Generator 3000!������������������������������������������������������������������������� 146
Inheritance, Subclasses, and More!������������������������������������������������������������������������������������� 154
vii
Table of Contents

Adding the Bells and Whistles��������������������������������������������������������������������������������������������� 162


The New and Improved Super Hero Generator 3000 Code!������������������������������������������������� 166
In This Episode!������������������������������������������������������������������������������������������������������������������� 171

Chapter 9: Introducing Other Data Structures������������������������������������������������������ 173


More Data Structures���������������������������������������������������������������������������������������������������������������� 174
What Are Tuples?����������������������������������������������������������������������������������������������������������������� 175
The Tuple Functions������������������������������������������������������������������������������������������������������������� 179
More Fun with Tuples���������������������������������������������������������������������������������������������������������� 182
Tuple Examples������������������������������������������������������������������������������������������������������������������� 185
Working with Dictionaries��������������������������������������������������������������������������������������������������� 188
Dictionary Methods������������������������������������������������������������������������������������������������������������� 190
More Fun with Dictionaries������������������������������������������������������������������������������������������������� 191
Other Dictionary Methods���������������������������������������������������������������������������������������������������� 194
Example Dictionary Code����������������������������������������������������������������������������������������������������� 195
In This Episode!������������������������������������������������������������������������������������������������������������������� 197

Chapter 10: Python Files�������������������������������������������������������������������������������������� 199


Working with Files in Python���������������������������������������������������������������������������������������������������� 200
File Types����������������������������������������������������������������������������������������������������������������������������� 202
Creating a Text File in Python Code������������������������������������������������������������������������������������� 203
Reading Files in Python������������������������������������������������������������������������������������������������������� 205
A Warning About Reading and Writing to Files�������������������������������������������������������������������� 208
Appending to Files��������������������������������������������������������������������������������������������������������������� 209
Working with Directories����������������������������������������������������������������������������������������������������� 211
Bonus Round!���������������������������������������������������������������������������������������������������������������������� 217
FunWithFiles.py Code���������������������������������������������������������������������������������������������������������� 218
WorkingWithDirectories.py�������������������������������������������������������������������������������������������������� 220
In This Episode!������������������������������������������������������������������������������������������������������������������� 221

viii
Table of Contents

Chapter 11: Python for Gaming���������������������������������������������������������������������������� 223


Python for Gaming�������������������������������������������������������������������������������������������������������������������� 224
Types of Games You Can Code in Python����������������������������������������������������������������������������� 225
Pygame Introduction����������������������������������������������������������������������������������������������������������� 225
Installing Pygame���������������������������������������������������������������������������������������������������������������� 226
Setting Up the Pygame Bare Bones for a Game������������������������������������������������������������������ 227
Adding to Our Game Skeleton��������������������������������������������������������������������������������������������� 228
Adding Images and Sprites in Pygame�������������������������������������������������������������������������������� 231
Adding Text to Our Pygame Game Window�������������������������������������������������������������������������� 236
Drawing Shapes in Pygame������������������������������������������������������������������������������������������������� 240
Adding More Events������������������������������������������������������������������������������������������������������������� 244
In This Episode�������������������������������������������������������������������������������������������������������������������� 254

Chapter 12: Animating Games������������������������������������������������������������������������������ 257


Creating Animations in Pygame������������������������������������������������������������������������������������������������ 257
Collision Detection: Bouncing off the Walls������������������������������������������������������������������������������� 264
Collision Detection: Detecting the Window Boundaries������������������������������������������������������������ 265
Colliding Two Objects���������������������������������������������������������������������������������������������������������������� 269
In This Episode!������������������������������������������������������������������������������������������������������������������������� 275

Chapter 13: Error Handling����������������������������������������������������������������������������������� 277


Finding Errors��������������������������������������������������������������������������������������������������������������������������� 278
Types of Errors�������������������������������������������������������������������������������������������������������������������������� 282
Syntax Errors����������������������������������������������������������������������������������������������������������������������� 282
Logical Errors���������������������������������������������������������������������������������������������������������������������� 283
Exceptions��������������������������������������������������������������������������������������������������������������������������� 285
The Try Except Else Block���������������������������������������������������������������������������������������������������� 287
Using Finally������������������������������������������������������������������������������������������������������������������������������ 288
Creating Custom Exceptions����������������������������������������������������������������������������������������������������� 289
Logging������������������������������������������������������������������������������������������������������������������������������������� 291

ix
Table of Contents

Debugging Tools in Python�������������������������������������������������������������������������������������������������������� 294


One Final Tip for Handling Errors���������������������������������������������������������������������������������������������� 295
In This Episode!������������������������������������������������������������������������������������������������������������������� 295

Chapter 14: Python Career����������������������������������������������������������������������������������� 297


Working with Python����������������������������������������������������������������������������������������������������������������� 299
Career Paths for Python������������������������������������������������������������������������������������������������������������ 299
Beta Tester��������������������������������������������������������������������������������������������������������������������������� 300
Code Debugger/Bug Locator����������������������������������������������������������������������������������������������� 300
Data Scientists�������������������������������������������������������������������������������������������������������������������� 301
Software Developer/Software Engineer������������������������������������������������������������������������������ 301
Video Game Programmer���������������������������������������������������������������������������������������������������� 301
Mobile Development������������������������������������������������������������������������������������������������������������ 302
Web Development and Web Applications���������������������������������������������������������������������������� 303
System Administration�������������������������������������������������������������������������������������������������������� 303
Research, Teaching, and More��������������������������������������������������������������������������������������������� 303
Common Python Interview Questions��������������������������������������������������������������������������������������� 304
Can You Tell Me Some of the Key Features of Python?�������������������������������������������������������� 304
What Is the Difference Between a Tuple and a List������������������������������������������������������������� 305
What Is Inheritance?������������������������������������������������������������������������������������������������������������ 305
How Do You Generate Random Values in Python?��������������������������������������������������������������� 305
How Do You Create a List, Tuple, and Dictionary in Python�������������������������������������������������� 306
What Is the Difference Between a Local Variable and a Global Variable?��������������������������������� 306
What Are the Different Data Types Python Offers?�������������������������������������������������������������� 306
What Is a GUI? What Python Library Is Best for GUI Development?������������������������������������� 306
How Do You Open a File in Python?������������������������������������������������������������������������������������� 307
How Would You List the Functions of a Module?����������������������������������������������������������������� 307
Other Python Interview Questions��������������������������������������������������������������������������������������������� 307
Best Programming Practices���������������������������������������������������������������������������������������������������� 308
Follow Style Guides������������������������������������������������������������������������������������������������������������� 308
If It’s Broken, Fix It (Now, Not Later)������������������������������������������������������������������������������������ 309
Documentation Is Everything����������������������������������������������������������������������������������������������� 309

x
Table of Contents

Use Code Repositories and Packages��������������������������������������������������������������������������������� 310


Test Often���������������������������������������������������������������������������������������������������������������������������� 310
Choose a Side: Indentation or Spaces��������������������������������������������������������������������������������� 311
Classes Are Great, But Not Everything Needs to Be One����������������������������������������������������� 311
The Future of Python����������������������������������������������������������������������������������������������������������������� 311
Python Terms���������������������������������������������������������������������������������������������������������������������������� 312

Index��������������������������������������������������������������������������������������������������������������������� 317

xi
About the Author
James R. Payne was introduced to programming when he was just 10 years old. He
started off hacking text-based games like Lemonade Stand to gain an advantage while
playing and soon started creating his own text-based role-playing games in the style of
Dungeons & Dragons and inspired by his favorite comic books. The enjoyment of those
early days stuck with him, and he continues to be drawn back into the programming
world throughout his career.
Payne is the former Editor-in-Chief/Community Manager of Developer Shed, an
online publication and community consisting of 14 websites and forums dedicated to
programming, web development, and Internet marketing. He’s written over a thousand
articles on coding and marketing, covering virtually every language and platform
available. His first book, Beginning Python (Wrox Press), was published in 2010. In
addition, he has published over 2000 articles covering topics ranging from gaming to
aerospace/aeronautics, and also writes adult horror and young adult fantasy books.
Payne decided to write this book to pass on his love of development in the hopes that
it would inspire future generations to code. You can find Payne on the web by visiting
www.jamesrpayne.com.

xiii
About the Technical Reviewer
Andrea Gavana has been programming Python for almost
16 years, dabbling with other languages since the late
1990s. He graduated from university with a master’s degree
in Chemical Engineering, and he is now a Lead Reservoir
Engineer working for Total in Copenhagen, Denmark.
Andrea enjoys programming at work and for fun, and
he has been involved in multiple open source projects, all
Python-based. One of his favorite hobbies is Python coding,
but he is also fond of cycling, swimming, and cozy dinners
with family and friends.
This is his third book as technical reviewer.

xv
Acknowledgments
This book wouldn’t have been possible without Todd Green, who reached out to me to
write a book and listened to my ideas and, thankfully, chose the one I wanted to write the
most.
Jill Balzano, Coordinating Editor extraordinaire, was invaluable in keeping things
rolling during an incredibly busy time, and without her, this book would never have
come to fruition either.
James Markham and Andrea Gavana found all of my errors and proved to me that,
even at this old age, I still have a lot to learn. Who knew – an old dog can learn new tricks.
Thank you to the entire editorial team at Apress, who were a pleasure to work
with and helped me do what I love to do most: write. And make up stupid comic book
characters.

xvii
Introduction
Who This Book Is For
This book is intended for teenagers looking to program in Python. While that technically
means anyone aged 13 through 18, the truth of the matter is, anyone of any age can (and
should, if I do say so myself!) pick up this book if they want to learn either (a) how to
program in Python, (b) how to program as a beginner, or (c) add Python to their current
skill set.
Above all, if you are holding this book in your hand, intrepid adventurer, then this
book is for you. The future is dependent on young heroes like yourself, eager to learn
the art of coding and go out into the world and safeguard it from nefarious hackers,
dubiously programmed applications, and the rise of artificially intelligent robots!
So whether you are in sixth grade or in college, this book will grant you with super
powers galore. Sure, you won’t be able to see through walls or lift cars over your head
once you finish this book. However, you will be able to speak the language of computers
and create some pretty cool programs.
And what could be better than that?

What You Will Learn in This Book


Chapter 1 provides an overview of programming and Python and then shows you how
to install Python and a Python IDLE, which will allow you to create your own Python
programs and test your code.
In Chapter 2, we will discuss mathematical functions (things like division,
addition, and multiplication) and learn about the different data types used by Python.
We will also begin to build the foundation of a fun super hero generator app – “Super
Hero Generator 3000”!
Chapter 3 delves into how to work with text – also known as strings. We take a look
at the different types of storage Python offers as well. We wrap things up by looking at
common string functions and build another section of our Super Hero Generator 3000
application.

xix
Introduction

Sometimes a program will need to take a certain action depending upon feedback
from a user or from other influences. This is known as decision making and is the topic
of Chapter 4.
Programming logic and loops – known as iterations, where code can “loop” or repeat
itself based on certain conditions – are covered in Chapter 5.
Chapter 6 is a refresher course of what you have learned up until this point. We will
use all the knowledge we’ve acquired to finish building the first complete version of
Super Hero Generator 3000. By the end, you will be able to randomly create heroes with
unique super powers, names, and battle statistics!
In Chapter 7, we begin to learn more advanced techniques. To be a real coder, you
must learn efficiency and reduce mistakes in your code. That is where modules and
built-in functions come into play. Learn what they are and why they will make your life a
whole lot easier in this exciting chapter!
Chapter 8 looks at even more advanced topics: specifically, we will cover the basics
of object-oriented programming (OOP) and cover objects and classes and define a thing
called polymorphism.
To switch things up a little bit, Chapter 9 will look at some different types of data
structures, including tuples and dictionaries.
Chapter 10 brings us up to speed on how to create – and work with – files inside of
directories.
One of my personal favorite chapters is Chapter 11, which covers a topic that is
near and dear to my heart: Python for Gaming. We will stroll through the world of video
games and learn how to work with video game elements, including sound, animation,
and more!
Learning how to create games that interact with a users actions and making images
move within a game are truly what make games enjoyable. Chapter 12 continues the
topic of gaming and focuses specifically on game animation.
In Chapter 13 – don’t worry, in this case 13 is lucky, for you at least! – we move into
areas of Python we have not yet discussed that do not fit in their own chapter. This
includes how to debug – or find broken code. We also look at advanced modules and
other topics.
Finally, we sum everything up in Chapter 14 and cover a wide range of topics,
including how to find work as a Python programmer, common interview questions, the
future of Python, and career paths, and answer some of the frequently asked questions
(FAQs) about our favorite programming language.

xx
Introduction

So now that we know what we will learn, let’s put on our cape and super hero outfits
and get ready to leap tall buildings – of knowledge.

Why I Started Programming


I started programming a long, long time ago – back before the Internet or cell phones
existed and when wild dinosaurs roamed the earth. Back then, computers didn’t have
images on them like they do today. Everything was text-based – even most of our games –
the horror! While we did have some computer games with animation and graphics, they
were 8-bit and not cinematic like the ones of today.
I was fortunate enough to share a computer with my older brother. I’m pretty certain
my parents didn’t know what a computer was used for, but must have thought: “This
future-device will surely make my children Men… of… the… Future… future… future…
future…” (just pretend the word is echoing).
And to some degree, they were correct: if they hadn’t purchased my brother and
me a computer, who knows what I would be doing with my life right now? Certainly not
writing this book and helping you to program like a hero!
But having a giant paperweight made of jumbled electronics – back then we called
it an Apple IIe – wasn’t enough to entice me to use it all that much. After all, I also
happened to own a Nintendo Entertainment System (NES) as well and it had an amazing
slew of games that I still – embarrassingly – play to this day.
What really got me into computers was this: I had a friend, Nicholas, who knew all
about programming computers. He showed me one day how to “hack” into the code
of a few of our favorite text-based games to give ourselves an advantage. It was akin to
creating your very own cheat code in a video game. In particular, we played a game called
Lemonade Stand, which was exactly the same as standing outside your house and selling
homemade Lemonade, only you never made real money and you didn’t get a sunburn.
In the game, you started out with a couple of dollars – barely enough to make any
real profit. However, once we looked at the code running the game, we figured out that
we could start out with however much money we wanted if we just changed a few words
around. Soon enough, I was the world’s first millionaire Lemonade Stand mogul.
I was hooked.

xxi
Introduction

From there, it was not a far stretch to conceive that we could actually create our
own video games and that is exactly what we did. From complex role-playing games
(RPG) based off of our favorite comic books and Dungeons & Dragons to programs that
would ask our friends a series of questions and then make fun of them based off of their
answers – shenanigans!
While all of that seemed silly at the time, looking back on it I now know that it helped
set the foundation for my love of programming and, to a degree, writing (though I began
writing much earlier than that). Without that summer of programming fun, I would
never have had the wonderful experiences, friends, jobs, and writing opportunities that
have come my way ever since.
And, mostly, I would never have had the fun of programming either.
That is what I am hoping to pass on to you, dear reader: a lifetime love of
programming and opportunities all based off of one thing – the fun and joy of writing
computer programs and writing code.
Sure, programming applications can be a pain in the butt. You will find yourself
banging your head against a keyboard on many nights and yelling at the computer
screen for hours only to find that your program isn’t working because you forgot a
parenthesis () somewhere.
But – once you find that mistake that you or another programmer made – there isn’t
quite anything like that triumphant moment when you realize that you – YOU – are the
greatest coder of all time!

Programming Dos and Don’ts


When reading this book, you may find yourself feeling the urge to skip ahead a little or
might want to skip an exercise or two. As in all things in life, this piece of advice holds
true in learning to program as well: if you cheat, you are only cheating yourself.
To help keep you on the straight and narrow, here are some dos and don’ts for
reading this book and for learning how to program, in general:
Do read the book straight through. While you might be okay to skip a chapter or an
exercise here or there, keep in mind that this book is all about building a foundation
of not just coding language, but coding practices, theory, and an understanding of
programming principles that you can take with you that apply to other languages as well.

xxii
Introduction

Don’t copy and paste code from this book or any other source (assuming you have a
digital copy). Instead, take the time to type in the code so that you can begin to get a feel
for writing code and, perhaps, commit some of the code to memory through repetition.
Do experiment with code. One of the best ways, I’ve found, to learn how to truly
code is to experiment. If you come across an example in the book, feel free to change the
parameters some and see what happens. The worst that can happen is that you can fail.
The best? That you learn something new!
Don’t be afraid to Google other tutorials and how-tos on Python. This book is
supposed to build a beginner’s foundation, but it does not teach you everything there is
to know – that’s what the sequel is for! If you do decide to look up comparative examples,
be certain to look at the date of the article and the version of Python. If the version does
not match the version we are using in this book (Python 3), odds are your code will not
work and you will find yourself very confused.
Do document your code. We have not covered this topic – yet – but for now, know
that documentation means to leave little comments in blocks, or sections, of your code
that lets you (or another coder in the future) know what you intended to do with a certain
section of code. While Python is a very readable language, the way every programmer
codes is different, and what might be apparent to you is not always apparent to others.
Also, if you have to review your own code at a later date, it will make it easier for you to
remember what, exactly, you were trying to do at 4 a.m. 10 years ago!
Do plan out your code. That is, write down how you want your overall program to
work and then break that down into little sections. Then, take those little sections and
map out what you need to code for each part. This way you will have a roadmap to follow
and won’t just be coding by the seat of your pants.
Finally, do test your code frequently and save your work often. When we
programmers are in the thick of things, we like to carry on, plugging away, for hours at a
time. However, if we don’t stop to test our code and save our files, we risk losing hours of
work and, worse, creating a program with problems that are difficult to trace.

xxiii
CHAPTER 1

Introduction to Computer
Programming and Python
Computer programming – commonly referred to as “coding” by the cool kids – is the
art of creating applications or software. These programs allow us to do everything from
solve simple math problems and watch our favorite YouTube videos (I can’t get enough
of skydiving bulldogs) to destroying hordes of rampant aliens in our favorite video games
and even launching a real-life spaceship into outer space.
I call computer programming an “art” because it is. Anytime you create something,
you are indulging in an art form. Sure, computer code, the words we type into a shell to
create our programs (more on this later!), may not be pretty to look at for the common
person on the street – your code will never see the inside of an art exhibit most likely –
but when a part of your program does what you created it to… there is almost nothing
more magical.
Well, maybe those skydiving bulldogs.
A computer program can come in many shapes and sizes. In addition to an
application that runs on your desktop system or a game that plays on your favorite video
game console, programs also take the form of mobile apps on a cell phone. You can even
find pieces of software that operate things like refrigerators, your mom’s minivan, and
even something as simple as a toaster oven.
And robots. Armies of robots.
But more on that later.
For now, know that a computer program is a set of code, created in a programming
language, that tells a device to carry out a set of instructions.

1
© James R. Payne 2019
J. R. Payne, Python for Teenagers, https://doi.org/10.1007/978-1-4842-4550-7_1
Chapter 1 Introduction to Computer Programming and Python

Programming Language Overview


As mentioned, a computer program is written using a programming language. Just like
the real language you, I, and the rest of the world speak every day, computer languages
come in all shapes and sizes. While most of them make sense to the trained eye, a
newcomer to code would sound like a crazy person spouting gibberish if they tried to
use it in everyday conversation. That dialogue might look something like this:

Normal Person: Hello, how are you?


Programmer (You): Print I am fine! Input, how are you?

Fortunately for all involved, computers are fluent in programming languages


(thanks, in part, to our friend the compiler – but more on this later!) and can easily
understand the most complex of sentences you type in.
For the purpose of this book, we will stick to one of the most versatile, yet easy-to-­
learn, languages, Python. While the name sounds frightening, keep in mind, it could
be worse: it could be called Cobra. In truth, the language was not named after a reptile
at all, but, instead, an old television comedy from Britain called Monty Python and the
Flying Circus.
Here’s your first assignment: Go ask your parents about that show. See you in a few
hours!
Oh, you are back. Great. Did what they said make any sense? Probably not. But that’s
okay; you don’t need to understand the complexities of British comedy to learn how to
program using this book. All you need is a desire to learn, a computer, and the pages in
front of you.

Python Overview
Python is what is known as a high-level, dynamic, interpreted, object-oriented
programming language. While all of that may sound a bit intimidating, never fear! By
the end of this book, you will be able to impress your friends with sentences much more
daunting than the one above! All that statement really means is that Python is not a
basic machine-level language, and as such, it needs an “interpreter” to “compile” it to
machine language so that the computer can understand what it is you are trying to tell it.

2
Chapter 1 Introduction to Computer Programming and Python

This interpreter takes your code and converts it – or compiles it – into a series of 1s
and 0s that a computer can plainly understand. All of that happens in the background, so
don’t worry if you do not quite understand it just yet.
Python is a relatively new programming language that was created in the late 1980s –
back when your dad had a big funny mustache and your mom listened to bands with
names like Wham! and Poison.
The man that created the language was a computer genius named Guido Van
Rossum, who was bestowed with the fancy, nonsensical title, Benevolent Dictator for
Life. Like technology, programming languages evolve as well, and Python is no different.
It has gone through several versions over the years and is currently known as Python 3.

 ow Does Python Differ from Other Programming


H
Languages?
Python differs from other programming languages in a number of different – yet
important – ways. For starters, Python is typically easier to learn and use than languages
in the same class, such as Java and C++. Programs created in Python also take less time
to create, as it requires less code (in general). This is due, in part, to Python’s data types –
a term we will cover in great detail in an upcoming chapter.
Python is also extremely versatile. While it may not be the primary choice, Python
can be used for applications in virtually every arena, including gaming, desktop software,
mobile apps, and even virtual reality. It is also a must for network programming and an
essential tool in a computer security toolbox.

The Benefits of Python


Python is currently the most-used programming language in the world today and is the
fastest growing as well. And with good reason. Below are just a few ways in which Python
can benefit a programmer:

• Increased productivity: By some reports, Python can increase a


programmer’s productivity – how much work they can accomplish
in a given time – by as much as ten times! It literally is faster than a
speeding bullet!

3
Chapter 1 Introduction to Computer Programming and Python

• Extensibility: One great advantage of Python is the fact that it has a


very extensive library of, well, libraries. A library is a set of existing
code you can add-in to your program. These libraries cover things
that are common features of a program and save you from having
to write the code over and over again yourself. For example, instead
of having to write a section of code to perform a complicated
mathematical equation, you can supply use a library and save
yourself a huge headache.
• Python is easy to read: One tough part of being a programmer is the
fact that, sometimes, your code does not work. When that happens,
you might find yourself re-reading your code – or worse, someone
else’s – to try and figure out why your program is not behaving as it
should. Fortunately, Python is easy to read and most of the language
makes sense at a glimpse. This makes finding issues a lot easier than
more complicated languages.

• Portability: Python runs on many platforms and systems, meaning


your programs can reach a wider audience.

• Internet of Things (IoT): The Internet of Things may sound like a


magical world full of digital beasts, and in some ways, it is. The IoT
consists of smart objects – light switches, doorknobs, toaster ovens,
appliances – that you find in your everyday home. These household
appliances are controllable by voice commands and mobile devices,
making them more interactive than their primitive predecessors.
I mean sure, your mom and dad yelled at the dishwasher all the
time – but did it ever listen? Now, thanks to the IoT and languages like
Python, it can! You still have to put your dishes inside of it, but still!

• Python frameworks: Frameworks are like skeletons for a program –


they allow you to quickly set up the basics for certain types of
applications without needing to code common elements that
usually exist in the type of software you are developing. This saves
programmers time and reduces the number of errors that can occur
when you have to manually code. Python is supported by a large
number of frameworks that can make launching a new program very
rapid indeed!

4
Chapter 1 Introduction to Computer Programming and Python

• Python is fun: Python is a fun language to learn; as stated, not only


is it easy to get started, but the Python community host many fun
events and challenges. For example, many people write their Python
code in poetry form and there are numerous Python “challenges”
released every year to help test a coder’s skills.

• Python is flexible: Because Python has so many uses and is used by


so many companies around the world, finding a job after learning
Python is easier than with other languages. In addition, if you do
not like a given field, you can always use your Python skills to try a
different path. For example, if you find that coding applications is
boring, you could switch to network administration or work at an IT
security firm.

And those are just a few of the benefits and advantages that Python offers.

Examples of Python in the Wild


While it is impossible to say just how many companies around the world use Python,
there are a number of interesting businesses that rely on the language. Below is just a
smattering of them:

• Wayne Enterprises (Batman’s Alter Ego’s corporation): Well, we don’t


really know that, but wouldn’t that be cool!

• Google: The search engine giant and one day ruler of the galaxy,
Google, has been using Python since its inception, partially because
developers can build programs so quickly with it and also because
the code is easy to maintain.

• Facebook and Instagram: While Python is not the only language used
at these two social media platforms, it is one of their most important
ones. Facebook uses Python, in part, thanks to its extensive libraries.
Instagram, meanwhile, is a firm supporter of one of Python’s main
web frameworks – Django. We cover web frameworks in great detail
later in this book.

5
Chapter 1 Introduction to Computer Programming and Python

• Netflix: If you are a fan of streaming movies, then you are no stranger
to Netflix. The company uses Python primarily for its data-analysis
capabilities and for security purposes – among other areas.

• Video games: Battlefield 2 and Civilization 4 are just two video games
that both rely on Python. Interestingly enough, Civilization uses
Python for, among other things, its artificial intelligence (AI) scripts.

• Government agencies and institutions: Government agencies and


institutions including NASA, The National Weather Service, and the
CIA all use Python – though how it is used is Top Secret! Meet us in
the garage with a briefcase full of money and we’ll tell you all about it!

Your First Python Program


By now, you are probably wondering what Python code looks like. Well, fear not! I
am going to show you a sample snippet. Later, after we install Python and an IDLE
(integrated development environment) on your computer, you can try and execute – or
run – the code to see it in action. For now, though, I thought it would be a good idea to
just give you a taste before delving any further into the language.
Traditionally, when a programmer writes their first ever line of code, they create a
program called, “Hello, World,” as a metaphorical way to introduce themselves to the
world. However, as budding super heroes – or villains (no judgment here) – we need
something a little flashier.
Behold, your first Python program!

print("Look up in the sky! Is it a bird? Is it a plane?")


print("Dun dun dun dun dun dun dun dun dun dun dun dun dun dun dun dun")
print("No you dummy. That's just some guy flying around in his pajamas. Now
get back to work!")

If you were to run this code, the result would be:

Look up in the sky! Is it a bird? Is it a plane?


Dun dun dun dun dun dun dun dun dun dun dun dun dun dun dun dun

No you dummy. That's some guy flying around in his pajamas. Now get back
to work!

6
Chapter 1 Introduction to Computer Programming and Python

Let’s examine the code a little more closely. The part that says print() is known
as a function, whose job it is to tell the computer to – in this case – print something to
the user’s screen. The text in between the opening and closing parentheses () is the
parameter that we are providing the function. The characters in between the quotation
marks “ ” are known as a string.
Don’t worry if this doesn’t make all the sense in the world just yet – we go over this
topic in great detail in the next chapter. For now, just know that this is what Python code
looks like. Odds are, you were able to tell exactly what this program would do before I
told you; that is just one of the things that make Python so great – its readability!

I nstalling Python
In this section, we are going to learn how to install Python on the various operating
systems. An operating system is a piece of software that lets you interact with a computer.
You are probably familiar with the more popular ones, such as Microsoft Windows (if
you own a PC) and Mac OS X if you own an Apple computer. The version of Python you
install will vary depending upon which one of these your computer uses. In addition, we
will learn how to install Python on Linux and Ubuntu systems as well.

Installing Python on Windows


To begin, open up a web browser and navigate to the official Python website and its
download page: www.python.org/downloads/ (Figure 1-1).

Figure 1-1. Python.org website


7
Chapter 1 Introduction to Computer Programming and Python

The current version of Python is 3.6.5; by the time you read this book, it may be
higher than that. Whatever the case, click the “Download Python” button under the
Download the Latest Version for Windows header. Optionally, you could scroll down and
download previous versions (just make sure they are version 3.X or higher, as there are
incompatibility issues between versions 2.X and 3.X); however, for the purposes of this
book, it is always best to use version 3.6.5 or later.
An image will appear asking if you would like to save the file. Click “Save File”
(Figure 1-2) and save it to your Desktop or somewhere easily remembered.

Figure 1-2. Save file dialogue for Python installation files

Navigate to your Desktop (or the location where you saved the file) and double-click
it. It should appear similar to the image in Figure 1-3.

Figure 1-3. Python .EXE install file icon

The installer will launch and will ask you whether you wish to “Install Now” or
“Customize Installation.” For ease, we are going to allow the installer to “Install Now.”
Before you click that button, however, make sure that “Install launcher for all users”
and “Add Python 3.6 to PATH” are both checked. Then click the “Install Now” option
(Figure 1-4).

8
Chapter 1 Introduction to Computer Programming and Python

Figure 1-4. Python install setup screen

You may get a pop-up from Windows asking for permission to continue the
installation. If so, allow the program to continue. A new pop-up will appear, showing you
the Setup Progress (Figure 1-5):

9
Chapter 1 Introduction to Computer Programming and Python

Figure 1-5. Python installation progress screen

Once Setup is complete, you will see a screen like the one below. Click the “Close”
button to complete installation (Figure 1-6).

10
Other documents randomly have
different content
an offence to the orthodox, let them accept it, without resentment,
as a little harmless fun—all art being that.
Having said so much I return to my own difficulty, for it is very hard
to focus H.G. Wells. He has passed through many stages and has
not yet attained the Olympian repose. Artist as he is, he has been
hotly entangled in practical affairs. There are signs in his early books
that he once shared what Richard Jeffries called the "dynamite
disposition,"—even now he knows, in imagination alone, the joy of
black destruction. He has also been, and ceased to be, a Fabian. But
it is plain that he has passed for good and all beyond the emotional
plane of propaganda. He has abandoned working-theories and the
deceptions of the intellect which make the man of action. He has
become at once more practical and more mystical than a party
programme permits one to be. Here is a world where things are
being done—a world of which capital and labor are but one
interpretation. How far can these things and the men who do them
be swept into the service of the race? That is the practical issue in
his mind, and the mystical issue lies in the intensity and quality of
the way in which he feels it.
To see him clearly one has to remember that he is not a synthetic
thinker but a sceptical artist, whose writings are subjective even
when they seem to be the opposite, whose personality is constantly
growing, expanding, changing, correcting itself ("one can lie awake
at night and hear him grow," as Chesterton says), and who believes
moreover that truth is not an absolute thing but a consensus of
conflicting individual experiences, a "common reason" to be wrought
out by constant free discussion and the comparison and interchange
of personal discoveries and ideas. He is not a sociologist, but, so to
say, an artist of society; one of those thinkers who are disturbed by
the absence of right composition in human things, by incompetent
draughtsmanship and the misuse of colors, who see the various
races of men as pigments capable of harmonious blending and the
planet itself as a potential work of art which has been daubed and
distorted by ill-trained apprentices. In Wells this planetary
imagination forms a permanent and consistent mood, but it has the
consistency of a mood and not the consistency of a system of ideas.
And though he springs from socialism and leads to socialism, he can
only be called a socialist in the fashion—to adopt a violently
disparate comparison—that St. Francis can be called a Christian.
That is to say, no vivid, fluctuating human being, no man of genius
can ever be embodied in an institution. He thinks and feels it afresh;
his luminous, contradictory, shifting, evanescent impulses may, on
the whole, ally him with this or that aggregate social view, but they
will not let him be subdued to it. As a living, expanding organism he
will constantly urge the fixed idea to the limit of fluidity. So it is with
Wells. There are times when he seems as whimsical as the wind and
as impossible to photograph as a chameleon.
Just here I should like to give what may be taken as his own view of
capital and labor socialism in relation to the constructive socialism he
himself has at heart. I am putting together certain brief passages
from The Passionate Friends:

I have come to believe now that labor problems are problems


only by the way. They have played their part in a greater
scheme.... With my innate passionate desire to find the whole
world purposeful, I cannot but believe that.... Strangest of
saviours, there rises over the conflicts of men the glittering
angular promise of the machine. There is no longer any need
for slavery, open or disguised. We do not need slaves nor toilers
nor mere laborers any more; they are no longer essential to a
civilization. Man has ridden on his brother man out of the need
of servitude. He struggles through to a new phase, a phase of
release, a phase when leisure and an unexampled freedom are
possible to every human being....
Human thought has begun to free itself from individual
entanglements and dramatic necessities and accidental
standards. It becomes a collective mind, a collective will towards
achievement, greater than individuals or cities or kingdoms or
peoples, a mind and will to which we all contribute and which
none of us may command nor compromise by our private
errors. It ceases to be aristocratic; it detaches itself from
persons and takes possession of us all. We are involved as it
grows free and dominant, we find ourselves in spite of
ourselves, in spite of quarrels and jealousies and conflicts,
helping and serving in the making of a new world-city, a new
greater State above our legal States, in which all human life
becomes a splendid enterprise, free and beautiful....
I have long since ceased to trouble about the economics of
human society. Ours are not economic but psychological
difficulties....

These last two sentences really tell the whole story. To pass from
economics to psychology is to pass from Man to men, from society
as a direct object of attack to the individuals who compose it. And
this marks the evolution of Wells the romancer and Wells the
expositor of socialist doctrine into Wells the novelist. It is the
problems of human interaction that occupy him now. But informing
these problems, reaching behind and embracing them, is a general
view of the world which has only become more intimate, more
personal, and more concrete with time.
When, in New Worlds for Old, Wells set himself to explain socialism
as he conceived it, he assumed as his first principle a certain Good
Will in men, an operating will steadily working in life toward
betterment. In other words, he supplemented the ordinary socialist
idea of economic determinism, which may or may not inevitably
bring about order on the industrial plane, with a constructive
purpose, which, in his view, can alone bring about the salvation of
the race. But this Good Will is not a fatality; it exists only by virtue of
remaining a conscious effort. In his experiments in Time and Space
Wells had accustomed himself to seeing that the immense
possibilities of what might be, so far as the universe is concerned,
predetermined things, were, so far as man is concerned, matters of
chance. To human society at least, if not to our planet, the most
unpropitious things are possible in the future; and there is no reason
to suppose that the destiny of the universe, which at every turn cuts
athwart the destiny of every species contained in it, should, left to
itself, work favorably to man.
This notion is in itself quite outside socialism and does not
necessarily lead into socialism. It was Huxley who said that the
world and the universe, society and nature, are demonstrably at
cross purposes, and that man has to pit his microcosm against the
macrocosm. Huxley, in his famous lecture on Ethics and Evolution,
went on from this to a kind of informal and unavowed socialism,
figuring society as a well-tended garden preserved by man's careful
art from the ravages and invasions of that hostile world of chance,
with its gigantic weeds and blind impulsions, which everywhere lies
waiting round about it. Our work, he implied, must be in every way
to minimize for ourselves the elements of chance, to become aware
of our species in a collective sense, battling with nature and
moulding our own future.
I do not suppose that Wells consciously adopted this idea from
Huxley. In itself that would be of little consequence, except so far as
it shows the continuity of thought and the development of socialism
out of science. But Wells was for several years a pupil of Huxley, and
it is reasonably plain that the mood in which he wrote his scientific
romances was strongly impregnated by Huxley's influence. The
sinister, incalculable, capricious, destructive forces outside man are
symbolized, as I have said, by those colliding comets, invading
Martians, and monstrous creatures among which the earlier Wells
moved and had his being; just as the sinister, incalculable, capricious
forces within man which urge him to destruction form so great a
part of his later novels. Most of his heroes (typified in The New
Machiavelli) come to grief through the blind irrational impulsions
within themselves. And he is equally haunted by what he has called
the "Possible Collapse of Civilization." I do not know how much this
is due to an evangelical childhood, in which Time, Death, and
Judgment are always imminent; how much to an overbalancing
study of science at the expense of the humanities; how much to an
overdeveloped sense of the hazard that life is; and how much to
plain facts. But there it is: it has always been a fixed conviction with
Wells that man personal and man social is dancing on a volcano.
Therefore he has come to socialism not by the ordinary course but
by a route obscure and lonely. The sense of possible catastrophe
and collapse, the folly of leaving things to chance, the infinite waste
and peril of committing our affairs to nature rather than to art—
these are some of the negative reasons that have made it impossible
for him to fall in with the non-socialist ideal in human affairs, that
"broadening down from precedent to precedent" which he calls
"muddling through": a doctrine that is wholly compatible with a
world of haphazard motives, accidental fortunes, accidental
management, a democratic individualism that places power in
irresponsible hands and suppresses talents that society cannot afford
to lose, a governmental system that concerns itself with legal and
financial arrangements, experts with no sense of a common
purpose, patriotisms that thrive on international bad feelings, and
that competitive principle which succeeds in the degree in which it
ignores the general welfare—a chaos of private aims, private virtues,
private motives, without any collective human design at all.
In the light of these opposed ideas of society as a thing of Chance
and as a thing of Design, let me run over two or three of the tales of
Wells.
First of all there is the special laissez faire of pure economic
determinism. The Time Machine pictures a possible result of the
Marxian process which has led to an irrevocable division of classes.
The rich, who were, in the old time, in comparison with the poor,
disciplined and united, have long since reached a point where work
and fear are for them things of the past. They occupy the surface of
the earth, and idleness and futility have made them light-headed,
puny, helpless creatures, stirring about and amusing themselves in
the sunlight. The poor, meanwhile, driven underground where they
burrow and tend machinery and provide, have lost all human
semblance and become white, horrible ghoul-like creatures that see
in the dark; at night they swarm out of their holes and feed upon
the creatures of the upper air. The one class has lost all power to
defend itself and the other all pity to spare, and gradually, year after
year, mankind comes to its end.
Then there is the ordinary laissez faire of capitalism, a result of
which is pictured in The Sleeper Awakes. The Sleeper, one recalls,
awakens four generations hence to find himself the master-capitalist,
owner of half the world, and the world is one where capital and
labor have irrevocably destroyed the possibility of a constructive
human scheme. But the responsibility for that future is very
ingeniously placed upon us of the present time; for Graham's
ownership of the world is the outcome of one of those irresponsible
whims that in our day characterize the whole individualistic view of
property. His cousin, having no family to inherit his possessions, has
left the whole in trust for the Sleeper, half in jest, expecting him
never to waken; and in time the trustees of this vested fund have
become the irresponsible bureaucrats of the world. "We were
making the future," says the awakened Sleeper, looking out upon
this monstrous outcome of whim and laissez faire; "and hardly any
of us troubled to think what future we were making."
Consider also The Empire of the Ants, in which Wells has figured a
possible reconquest of man by nature, owing to the greater
collective discipline of at least one non-human species. He imagines
a species of poisonous ants with only a little greater faculty of
organized co-operative intelligence than ordinary ants, which have
terrorized and finally routed several villages of unintelligent and
unorganized Brazilian natives far up the Amazon. The Brazilian
government sends against them an outworn inefficient gunboat, with
an incompetent captain and a muddle-headed crew; and when they
arrive the ants fall upon the only man sent ashore and sting him to
death. The captain repeats over and over, "But what can we do?"
And at last with tremendous decision he fires a gun at them and
retires. The story ends with a report that the ants are swarming all
over the interior of Brazil and that nobody knows how to prevent
them from occupying the whole of South America.
And then there is The History of Mr. Polly. I ignore for the moment
the individual aspect of his case, for Mr. Polly is not merely an
individual—he is an emblem of the whole, he is society in concreto.
We find him at the opening of the book sitting on a stile, suffering
from indigestion and consequently depressed in spirits. It is two
o'clock of a Sunday afternoon, and he has just finished his mid-day
meal. He has eaten cold potatoes, cold pork, Rashdall's mixed
pickles—three gherkins, two onions, a small cauliflower head and
several capers; cold suet pudding, treacle and pale cheese, three
slices of grey bread, and a jug of beer. He hates himself, he hates
his wife, he hates existence. But Mr. Polly's interior, the things that
have gone into it and the emotions that rise out of it, are only typical
of an entire life that has, to quote Macaulay's eulogy of the British
constitution, thought nothing of symmetry and much of
convenience.
Each of the novels of Wells, in one aspect at least, presents the
accidental nature of our world in some one typical case. Love and
Mr. Lewisham shows how in the case of one of those young students
who have, as things are, no chance at all, but who are the natural
builders of a better world, the constructive possibility is crushed by
the primary will to live. At eighteen Mr. Lewisham is an assistant
master at one of those incompetent private-enterprise schools which
for Wells (as also for Matthew Arnold) epitomize our haphazard
civilization. He has a "future"—the Schema which he pins to his
bedroom wall promises unimaginable achievements. He marries, and
you feel that he should marry and that he has married the right
person. But then with interests divided he has to find money and in
doing so he fails in his examinations. At last it becomes a choice
between his career and his children, between the present and the
future, and the children and the future win. Society loses just in the
degree that Lewisham himself loses, for he was fitted to be a
builder; and society has first, in the face of all his efforts, imperfectly
equipped him and then consistently refused to take advantage of his
talents.
Just as Lewisham is a potential builder of society who is defeated, so
Kipps is a specimen of the raw material, the muddled inferior
material with which society has to deal and refuses to deal. Kipps,
like Mr. Polly, is from the beginning a victim of accident, spawned on
the world, miseducated, apprenticed at fourteen to a Drapery
Bazaar. He grows up ignorant, confused, irresponsible; and then
suddenly, as accidentally as he was born, has £26,000 and
responsibility thrust upon him. The fortune of Kipps lifts him at once
out of the obscure negligible world of the populace and makes him a
figure to be reckoned with. Therein lies the comedy of the book. He
tries to make himself what in his own view a man of means ought to
be; naturally he sees money not as a force but as a thing to be
spent, and he finds that even from this point of view he has no
freedom of will, and that his lack of training inevitably places him in
the hands of equally irresponsible persons who want his money. He
wishes to build a house, designed after his own vaguely
apprehended needs and desires, and somehow under the wand of
the architect a house with eleven bedrooms springs from the
ground, a house plainly far beyond his own or Ann's power of
management, and the prospect of disrespectful servants, terrifying
callers, and a horde of scheming lawyers, tradesfolk and satellites.
And the life of Kipps under prosperity is summed up in the following
dialogue:

"Wonder what I shall do this afternoon," said Kipps, with his


hands deep in his pockets.
He pondered and lit a cigarette.
"Go for a walk, I s'pose," said Ann.
"I been for a walk this morning."
"S'pose I must go for another," he added after an interval.

May one suggest how the significance of such a story as this varies
according to the point of view? In the ordinary literature of comedy,
Kipps would be merely a parvenu whose want of dignity and
ignorance of the right use of money are laughable—or, if the novelist
were a humanitarian, pitiful. To the socialist, on the other hand,
every incident of his life, every gesture of his mind, is a unique
indictment of things as they are. He stands for the whole waste of
human stuff in a world which has not learned how to economize
itself, whose every detail is accidental in a general chaotic absence
of social design.
In this aspect Tono-Bungay is the most powerful work of Wells. Just
as his romances of the future had exhibited the possible effects of
accidental heedless social conduct in the past, so his novels exhibit
the motives that produce this heedlessness to consequences. Thus
the world in which the Sleeper awakes, a world irrevocably ruled by
the bureaucratic trustees of an irresponsible private fortune, is just a
conceivable consequence of such a career as Uncle Ponderevo's, had
not catastrophe overwhelmed him and enabled Wells to point a
much more pregnant moral. Tono-Bungay is a great epic of
irresponsible capitalism from the socialist point of view. Uncle
Ponderevo is a born commercial meteor, and when he first enters
the book, a small druggist in a dead country town, he exhibits the
temperament of a Napoleon of finance spoiling for conquest. He
wants to Wake Up Wimblehurst, invent something, do something,
shove something.

He indicated London as remotely over the top of the dispensing


counter, and then as a scene of great activity by a whirl of the
hand and a wink and a meaning smile at me.
"What sort of things do they do?" I asked. "Rush about," he
said. "Do things! Somethin' glorious. There's cover gambling.
Ever heard of that, George?" He drew the air in through his
teeth. "You put down a hundred, say, and buy ten thousand
pounds' worth. See? That's a cover of one per cent. Things go
up one, you sell, realize cent per cent; down, whiff, it's gone!
Try again! Cent per cent, George, every day. Men are made or
done for in an hour. And the shoutin'!... Well, that's one way,
George. Then another way—there's Corners!"
"They're rather big things, aren't they?" I ventured.
"Oh, if you go in for wheat and steel—yes. But suppose you
tackled a little thing, George. Just some leetle thing that only
needed a few thousands. Drugs, for example. Shoved all you
had into it—staked your liver on it, so to speak. Take a drug—
take ipecac, for example. Take a lot of ipecac. Take all there is!
See? There you are! There aren't unlimited supplies of
ipecacuanha—can't be!—and it's a thing people must have.
Then quinine again! You watch your chance, wait for a tropical
war breaking out, let's say, and collar all the quinine. Where are
they? Must have quinine, you know—Eh? ...
"Lord! there's no end of things—no end of little things. Dill-
water—all the suff'ring babes yowling for it. Eucalyptus again—
cascara—witch hazel—menthol—all the toothache things. Then
there's antiseptics, and curare, cocaine....
"Rather a nuisance to the doctors," I reflected.
"They got to look out for themselves. By Jove, yes. They'll do
you if they can, and you do them. Like brigands. That makes it
romantic. That's the Romance of Commerce, George."
He passed into a rapt dream, from which escaped such
fragments as: "Fifty per cent, advance, sir; security—to-
morrow."
The idea of cornering a drug struck upon my mind then as a
sort of irresponsible monkey trick that no one would ever be
permitted to do in reality. It was the sort of nonsense one would
talk to make Ewart laugh and set him going on to still odder
possibilities. I thought it was part of my uncle's way of talking.
But I've learnt differently since. The whole trend of modern
money-making is to foresee something that will probably be
needed and put it out of reach, and then to haggle yourself
wealthy. You buy up land upon which people will presently want
to build houses, you secure rights that will bar vitally important
developments, and so on, and so on. Of course the naïve
intelligence of a boy does not grasp the subtler developments of
human inadequacy. He begins life with the disposition to believe
in the wisdom of grown-up people, he does not realize how
casual and disingenuous has been the development of law and
custom, and he thinks that somewhere in the state there is a
power as irresistible as a head master's to check mischievous,
foolish enterprises of every sort. I will confess that when my
uncle talked of cornering quinine, I had a clear impression that
any one who contrived to do that would pretty certainly go to
gaol. Now I know that any one who could really bring it off
would be much more likely to go to the House of Lords!

And such or nearly such is this career. Tono-Bungay, that swindling


patent medicine without value or meaning, is the insubstantial
hippogriff upon which Uncle Ponderevo soars upward on the wind of
advertisement. In a society whose basis is unlimited individual rights,
he is able to disorganize the industrial world and to work out his
absurd, inept, extravagant destiny, scattering ruin right and left.
But the spirit of Good Will, the disinterested constructive spirit of
socialism which is the underlying assumption of Wells, appears here
as in all his later books. Out of the wreckage the constructive
purpose emerges, in the person of George Ponderevo. It shapes
itself as a steel destroyer, the work of an engineer's brain, a
destroyer which England has refused and which plunges down the
Thames to the open sea, the symbol of man's intentions, without
illusions and without the hope of personal gain, the disinterested
spirit of science and truth.

CHAPTER III

SOCIALISM TRUE AND FALSE


In the development of intellectual modesty lies the growth of
statesmanship. It has been the chronic mistake of statecraft and
all organizing spirits to attempt immediately to scheme and
arrange and achieve. Priests, schools of thought, political
schemers, leaders of men, have always slipped into the error of
assuming that they can think out the whole—or, at any rate,
completely think out definite parts—of the purpose and future of
man, clearly and finally; they have set themselves to legislate
and construct on that assumption, and, experiencing the
perplexing obduracy and evasions of reality, they have taken to
dogma, persecution, training, pruning, secretive education, and
all the stupidities of self-sufficient energy.

The man who wrote that is not what is called a whole-hearted man
as regards any form of group-action. He does not "fit in." He is at
bottom a sceptic, and a sceptic is one who reduces every question to
the question of human nature. So that the socialism of Wells is
necessarily at variance with all the recognized group-forms of
socialism, Administrative, Philanthropic, and Revolutionary. I must
briefly indicate in each case what is the quality of this divergence.
As regards the first, he has a complete distrust of what Hilaire Belloc
has called the "Servile State;" and what he distrusts he virulently
dislikes. In his view, Administrative socialism, as it appears in Sidney
Webb and the Fabian Society, and in the tendency of contemporary
Liberalism, has led to an excessive conservatism toward the existing
machinery of government, it has depended altogether too much on
organization without popular support, and as a result has tended to
throw the whole force of the socialist movement into a bureaucratic
regime of small-minded experts. The activity of the Fabians
especially, he says, has set great numbers of socialists working in
the old governmental machinery without realizing that the machinery
should have been reconstructed first. The whole tendency of this
method, as it is exhibited in the works of the English Liberal Party of
to-day, is toward a socialization of the poor without a corresponding
socialization of the rich; toward a more and more marked chasm
between the regimented workers and the free employers.
And it throws the control of affairs into the hands of a mass of highly
specialized officials, technical minds, mutually-unenlightened
experts. In an age when the progress of society depends upon
breaking down professional barriers, when the genuine scientist, for
instance, is a man who passes beyond his own science and sees the
inter-relationships of all knowledge, the mind which has been trained
in one habitual routine is the most dangerous type of mind to place
in authority. On the one hand, society depends upon the coöperation
of all sorts of specialists, their free discussion, and comparison of
methods, results, and aims; on the other experts in office are apt to
grow narrow, impatient, and contemptuous, seeing nothing beyond
their immediate work,—and this particularly when they have been
trained for administration without any wide experience of the world.
Therefore upon experts as such, in distinction from constructive and
coöperating specialists, Wells, with all the force of his belief in the
ventilating of knowledge and the humanizing of affairs, wages an
unceasing war. The First Men in the Moon satirizes, after the fashion
of Swift, a world where the expert view of life, not only in
administration but in all work, prevails. Each inhabitant of the Moon
has a single rigidly defined function, to which everything else in his
nature is accommodated. Thus certain types of machine-menders
are compressed in jars, while others are dwarfed to fit them for fine
work, "a really more humane proceeding", as Mr. Cavor observes,
"than our method of leaving children to grow into human beings and
then making machines of them." And in The Great State he returns
to his attack on government by experts: "Whatever else may be
worked out in the subtler answers our later time prepares, nothing
can be clearer than that the necessary machinery of government
must be elaborately organized to prevent the development of a
managing caste in permanent conspiracy, tacit or expressed, against
the normal man." And he adds: "The Great State will, I feel
convinced, regard changes in occupation as a proper circumstance in
the life of every citizen; it will value a certain amateurishness in its
service, and prefer it to the trite omniscience of the stale official."
One of the many and increasing indications, one might suggest, of
the remarkable tendency in Wells to find good in the old humanistic
Tory, as distinguished from the modern bureaucratic Liberal, view of
life.
But lest I be tempted to carry this latter suggestion too far just at
this point, I pass on to his equally virulent dislike of Philanthropic
socialism and the busy Superior Person in affairs; especially the type
of political woman so dear to Mrs. Humphry Ward's heart. If the
expert bureaucratic point of view represents the action of socialist
thought on the Liberal Progressive mind, so also the philanthropic
superior point of view represents the action of socialist thought on
the Conservative mind. It is arrogant, aggressive, and
condescending. It implies the raising of one's inferiors, and what
weak mortal should assume that she (for this happens to be a
mainly feminine affliction) is the standard according to which other
mortals ought to be raised?
Two of these energetic ladies have been pictured with a bitter
vividness by Wells in Altiora Bailey and Aunt Plessington, the former
summing up the Fabian-expert view, the latter summing up the
Superior-philanthropic view. Altiora has "P.B.P."—pro bono publico—
engraved inside her wedding ring. All the misery of the world she
marshals invincibly in statistics. She sees everything as existing in
types and classes; she pushes her cause with a hard, scheming, and
wholly self-centred eagerness, managing political dinners,
indefatigably compiling blue-books, dreaming of a world nailed as
tightly and firmly under the rule of experts as a carpet is nailed with
brass tacks.
On the other hand Aunt Plessington is the incarnation of a
"Movement" somewhat vague in purpose but always aggressively
beneficial to the helpless ones of the earth. "Her voice was the true
governing-class voice, a strangulated contralto, abundant and
authoritative; it made everything she said clear and important, so
that if she said it was a fine morning it was like leaded print in the
Times." Her mission is principally to interfere with the habits and
tastes of the working-class, making it impossible for them to buy
tobacco and beer or "the less hygienic and more palatable forms of
bread (which do not sufficiently stimulate the coatings of the
stomach)." She is, in short, one of those odious managing people
who know nothing of and care nothing for human nature, who
concern themselves wholly with the effects without penetrating to
the causes of misery, who see mankind as irrevocably divided into a
governing and a governed class, and whose idea of government is to
make the governed as uncomfortably efficient as possible and as
lacking in free will. She is exactly one of those arrogant sterile souls,
in love with methods rather than men, who have made the Servile
State an imminent and horrid possibility and have turned so many
misinformed human beings (including Tolstoy) against socialism
altogether.
If Wells dislikes Administrative and Philanthropic socialism because
they are not sufficiently human, he has an equal aversion to what is
called orthodox, that is to say, Revolutionary socialism; and in this
he includes all socialism that is fundamentally economic. "I have
long since ceased to trouble about the economics of human society,"
says Stratton in The Passionate Friends, in words we are justified in
taking as the opinion of Wells himself. "Ours are not economic but
psychological difficulties."
That statement is full of meaning. It expresses, not a fact but a
personal conviction—the personal conviction with which the
psychological constructive socialism of Wells begins. But before I
pass on to this I must make one comment that persists in my mind.
Nothing is more remarkable than the unanimity with which during
the last few years the advanced world has put all its eggs in the
basket of pragmatism, the basket that has been so alluringly
garnished by Bergson's Creative Evolution, In this movement of
thought Wells has inevitably become one of the leaders, and his
practical desertion of the socialist cause is one of the main
symptoms of it. The creative energies of men, where society as a
whole is concerned, are, in this philosophy, conceived as bursting
through the husks and institutions of the world, not consciously
destroying them but shedding them incidentally and passing on.
Now as regards sociology there is an obvious fatalism in that; for the
burden of proof lies once more on a personal basis, on a personal
basis qualified by the capacity of the person. It is true that this
creative and constructive tendency, like the total tendency of
modern life, is in the direction of socialism, it is true that a thousand
elements in modern life which could never be engaged in the class-
war are led by it into line with socialism. Yet there capitalism is! Only
the black-browed Marxian steadily contemplates the fact that year by
year the rich compound their riches and the poor their poverty, while
those that have no chance of creative outlets plant dynamite.
I do not mean that Wells is "wrong" in abandoning the economic for
the psychological approach,—that is plainly the inevitable course for
him. I wish simply to mark a distinction. The gospel of Wells is an
entirely personal one; it frankly concerns itself with the inner
realities of the human mind, and in that lies its great importance.
But let us discriminate. Like every purely personal doctrine it
contains, in relation to the facts and causes of society, a certain
quietism. It withdraws the mind from corporate action and lays
emphasis on corporate thought. But it recognizes no corporate
enemy. To be an opponent of capitalism as such, is, in this
philosophy, as quaint and crude and crusty as to be an anti-suffragist
or a believer in politics (for it has become the fashion to believe with
fervor in the franchise and scarcely to believe at all in what the
franchise stands for).
There is then a certain danger in the creative pragmatism of this
particular time. If it actually does penetrate to the head men of the
world, if it is able to generate what I suppose may be called a "moral
equivalent" of duty—and there is almost a probability that it will—the
hazard is won. If it does not—and many keen thinkers and men of
action are obdurate—then we shall simply have the fait accompli
with compound interest. What if it should turn out in the end, after
the best brains of socialism had all withdrawn from the economic
programme of socialism, that capitalism grows all the greener in the
sunlight of their tacit consent? There is Congress, there is
Parliament, and there they propose to remain. Suppose they are not
converted from the top? Is it altogether wise to stop persecuting
them from the bottom?
So much before I pass on. This comment does not qualify the
teaching of Wells. It merely supplements it from the economic side,
and the supplement seems to me an important one.
Of a piece with his whole point of view is that he calls the right
sociological method not a scientific but an artistic method: it consists
of the making and comparing of Utopias. This idea he sets forth in
his paper The So-called Science of Sociology. "What is called the
scientific method," he says, "the method of observation, of theory
about these observations, experiments in verification of that theory
and confirmation or modification, really 'comes off' in the sciences in
which the individuality of the units can be pretty completely
ignored." The method that is all-important in the primary physical
sciences where the individuality of atoms and molecules may
conveniently be ignored for the sake of practical truth, becomes in
his view proportionately untrue as the sciences in their gradation
approach the human world. "We cannot," he says in First and Last
Things, "put humanity into a museum and dry it for examination;
our one still living specimen is all history, all anthropology, and the
fluctuating world of men. There is no satisfactory means of dividing
it and nothing in the real world with which to compare it. We have
only the remotest idea of its 'life-cycle' and a few relics of its origin
and dreams of its destiny." And in the paper I have just mentioned
he speaks of the Social Idea as a thing "struggling to exist and
realize itself in a world of egotisms, animals, and brute matter....
Now I submit it is not only a legitimate form of approach, but
altogether the most promising and hopeful form of approach, to
endeavor to disentangle and express one's personal version of that
idea, and to measure realities from the standpoint of that realization.
I think, in fact, that the creation of Utopias—and their exhaustive
criticism—is the proper and distinctive method of sociology." This
notion of sociology as properly artistic in method and diagnostic in
aim indicates his main divergence from the methods and aims of
Comte and Spencer.
And so one turns to his own illustration of this belief, A Modern
Utopia. It is a beautiful Utopia, beautifully seen and beautifully
thought; and it has in it some of that flavor of airy unrestraint one
finds in News from Nowhere. Morris, of course, carries us into a
world where right discipline has long since produced right will, so
wholly and instinctively socialized that men can afford to be as free
as anarchists would have the unsocialized men of our own time, a
world such as Goethe had in mind when he said: "There is in man a
force, a spring of goodness which counterbalances egoism; and if by
a miracle it could for a moment suddenly be active in all men, the
earth would at once be free from evil." Well, that is the miracle
which has in some way just taken place before the curtain goes up
on most Utopias; and I think that Wells has never been more skilful
than in keeping this miracle quietly in his bag of tricks and devising
meanwhile a plausible transition between us and that better world.
It all happens in a moment and we are there. By an amazing
legerdemain of logic he leaps the gap and presents us with a planet
which at every point tallies with our own. It is a planet which does
not contain a State but is a State, the flexible result of a free social
gesture.
Mankind in the Making should be taken as introductory to A Modern
Utopia. It is the sketch of a method towards attaining such a world
state. It is a kind of treatise on education based on the assumption
that "our success or failure with the unending stream of babies is the
measure of our civilization." It opens with a complete repudiation of
"scientific" breeding, as a scheme which ignores the uniqueness of
individual cases and the heterogeneous nature of human ideals. "We
are," says Wells, "not a bit clear what points to breed for, and what
points to breed out;" while the interplay of strong and varied
personalities we desire is contradictory to any uniform notions of
beauty, capacity, and sanity, which thus cannot be bred for, so to
speak, in the abstract. But in A Modern Utopia he outlines certain
conditions limiting parentage, holding it necessary that in order to be
a parent a man must be above a certain minimum of capacity and
income, failing which he is indebted to the State for the keep of his
children. Motherhood is endowed and becomes in this way a normal
and remunerative career, which renders the mother capable of giving
her time to the care and education of her children, as millions are
not in a wage-earning civilization, and makes both her and her
children independent of the ups and downs of her husband. His very
detailed suggestions about the education of young children
(illustrated also in The Food of the Gods) are at once a reminiscence
of Rabelais and an anticipation of Madame Montessori. He insists
upon uniform pronunciation (a very important matter in England,
where diversity of language is one of the bulwarks of a rigid class-
system), the universality and constant revision of text-books, the
systematic reorganization of public library and bookselling methods,
with a view to making the race think as a whole. He urges the
necessity of rescuing literature from the accidents of the book-
market by endowing critical reviews, chairs for the discussion of
contemporary thought, and qualified thinkers and writers regardless
of their special bias or principles. To strike a mean between the
British abuse of government by hereditary privilege and the
American abuse of government by electoral machines he ingeniously
proposes the election of officials by the jury method, twenty or thirty
men being set aside by lot to determine the proper holders of office.
And he is convinced of the importance in a democracy of abundant
honors, privileges, even titles, and abundant opportunities for fruitful
leisure.
I have already spoken of his belief that the right sociological method
is the creation and comparison of individual Utopias. Thus his own
free-hand sketch of a better world is, in fact, a criticism of all
previous works of the kind. As distinguished from them the modern
Utopia, he says, has to present not a finally perfect stage but a
hopefully ascending one; it has to present men not as uniform types
but as conflicting individualities with a common bond; and moreover
it has to occupy, not some remote island or province "over the
range" but a whole planet. The Utopia of Wells is a world which
differs from the present world in one fundamental respect only—it
has one initial advantage: that every individual in it has been started
right, in the degree in which the collective knowledge of the world
has rendered that possible.
But there is no need for me to say anything more about these
books. They are the free and suggestive motions of a mind
inexhaustibly fertile and given to many devices. Anyone who has
read Wells at all is aware of his ingenuity, his equal capacity for large
schemes and minute details, his truly Japanese belief in radical
changes, once they are seen to be necessary and possible. And
indeed the details of social arrangement follow naturally and
profusely enough, once you get the frame of mind that wishes them.
Wells in his Utopia presupposes the frame of mind. In short, he puts
education first; he believes that the essential problems of the
present are not economic but psychological.
And here where the constructive theory of Wells begins, let me
quote a passage from The New Machiavelli that gives the gist of it:

The line of human improvements and the expansion of human


life lies in the direction of education and finer initiatives. If
humanity cannot develop an education far beyond anything that
is now provided, if it cannot collectively invent devices and solve
problems on a much richer, broader scale than it does at the
present time, it cannot hope to achieve any very much finer
order or any more general happiness than it now enjoys. We
must believe, therefore, that it can develop such a training and
education, or we must abandon secular constructive hope. And
here my initial difficulty as against crude democracy comes in. If
humanity at large is capable of that high education and those
creative freedoms our hope demands, much more must its
better and more vigorous types be so capable. And if those who
have power and scope and freedom to respond to imaginative
appeals cannot be won to the idea of collective self-
development, then the whole of humanity cannot be won to
that. From that one passes to what has become my general
conception in politics, the conception of the constructive
imagination working upon the vast complex of powerful people,
enterprising people, influential people, amidst whom power is
diffused to-day, to produce that self-conscious, highly selective,
open-minded, devoted, aristocratic culture, which seems to me
to be the necessary next phase in the development of human
affairs. I see human progress, not as the spontaneous product
of crowds of low minds swayed by elementary needs, but as a
natural but elaborate result of intricate human
interdependencies, of human energy and curiosity liberated and
acting at leisure, of human passions and motives, modified and
redirected by literature and art.

This permeation of the head men of the world, this creation of a


natural collective-minded aristocracy appears now to be the
permanent hope of Wells. It is the stuff of all his novels, it is the
centre of his ethical system; and his Utopia is made possible by the
existence in it of just such a flexible leading caste—the so-called
Samurai. But before coming to the inner implications of this, to the
individual and personal realities and difficulties of this, I must follow
the development of the idea in Wells himself. At various times, in
various works, he has presented it from a dozen different angles: as
something that is certain to come, as something he greatly desires
to come, as something that will not come at all except through
prodigious effort, as something that will come through a general
catastrophe, as something that will come through isolated individual
endeavor, and the like. That is to say he has presented his idea
through all the various literary mediums of exposition, fable,
prophecy, psychological analysis, and ethical appeal.
It appears in a crude form in his first avowedly sociological work,
Anticipations. He there attempts to show that the chaos of society is
of itself beginning to generate a constructive class, into whose hands
it must ultimately fall. The advance of mechanism, he predicts, will
produce four clearly defined classes: an immense shareholding class
with all the potentialities of great property and a complete lack of
function with regard to that property; a non-producing class of
middle-men dependent on these, and composed of agents,
managers, lawyers, clerks, brokers, speculators, typists, and
organizers; the expropriated class of propertyless and functionless
poor, whose present livelihood is dependent on the fact that
machinery is not yet so cheap as their labor. And amid this generally
disorganized mass a fourth element will define itself. This in
rudiment is the element of mechanics and engineers, whose work
makes it necessary for them to understand the machines they are
making and to be continually on the lookout for new methods. These
men, he holds, will inevitably develop a common character based on
a self-wrought scientific education and view of life. About them as a
nucleus all the other skilled and constructive minds—doctors,
teachers, investigators, writers, and the like—will tend to group
themselves; and as the other classes in their very nature will tend to
social disintegration, these will inevitably grow more and more
conscious of a purpose, a reason, a function in common, and will
disentangle themselves from the aimless and functionless masses
about them. Democracy, as we know it, will meanwhile pass away.
For democratic government unavoidably reduces itself to
government by party machines and party machines depend for their
existence on alarms, quarrelsome patriotisms, and international
exasperations whose almost inevitable outcome is war.
Whether war follows or not, the power of society is bound to fall into
the hands of the scientifically trained, constructive middle class,
because this class is the only indispensable element in it. Without
war this must occur just as soon as the spending and purchasing
power of the shareholding class becomes dependent for its existence
on the class which alone can save society from destruction. With war
it will occur with even greater rapidity: for in the warfare of the
future that nation is bound to win which has most effectively realized
socialist ideals, in which the government can command, with least
interference from private control, its roads, its food, its clothing, its
material, its resources, which has most efficiently organized itself as
a whole; and the class that modern warfare will bring to the front is
the class that knows how to handle machinery and how to direct it.
But just as this class will be the most efficient in war, so will it be the
most careful to prevent war: it will in fact confirm the ultimate
tendency toward a World State at peace with itself, through the
agency, not of any of the governments that we know to-day but of
an informal coöperative organization which is altogether outside the
governmental systems of society, and which may in time assimilate
the greater part of the population of the world.
Such is the argument of this book, and except for the inevitability of
it—the belief that all this must come to pass—Wells has not since
abandoned it in any essential way. The new aristocracy that figures
there, the advance-guard of a better civilization, is precisely the
ethical ideal which is embodied in the chief characters of his novels.
Thus too the Samurai of A Modern Utopia are figured as having
arisen at first informally as the constructive minds disentangling
themselves from the social chaos. Gradually becoming aware
through research, discussion and coöperation of a common purpose,
they have at last assumed a militant form and supplanted the
political organizations of the world.
The general intention of all this finds utterance in the most poetic of
all the fables of Wells, The Food of the Gods. The Food itself,
invented by two undistinguished-looking scientists, becomes current
in the world through the very haphazardness of a society which will
not control discoveries detrimental to it and which consequently has
no means of coping with a discovery capable of superseding it.
"Heracleophorbia" has thus the same initial advantage as Tono-
Bungay or any other shabby patent medicine. It has an additional
advantage; for while patent medicines have the sanction of private
enterprise and are controlled by secret patents for the gain of their
inventors, the Food of the Gods, like every discovery of honorable
scientists, is given freely to the world. Thus the Food and the
gigantic race of supermen who spring from it and bring with them a
nobler order of things are themselves generated by the very chaos
they promise to supplant. Just in proportion as the inventors are
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