includes the learning experience. The ultimate goal of this book is to spark your imagination and
lead you to develop interesting projects of your own. Don’t worry if they seem too ambitious at first;
a little diligence and a lot of googling can work miracles—and faster than you think.
The following is an overview of the chapters in this book. You don’t have to work through them
sequentially, but the easiest projects are at the beginning, and I explain new concepts, modules, and
techniques more thoroughly when they’re first introduced.
Chapter 1: Silly Name Generator This warm-up project introduces the Python PEP 8 and
PEP 257 style guides as well as the Pylint and pydocstyle modules, which analyze your code’s
conformance to these guidelines. The end product is a goofy-name generator inspired by the
USA Network TV show Psych.
Chapter 2: Finding Palingram Spells Learn how to profile your code while saving DC
Comics sorceress Zatanna from a painful death. Search online dictionaries for the magical
palingrams that Zatanna needs to beat a time-reversing villain.
Chapter 3: Solving Anagrams Write a program that helps a user create a phrase anagram
from their name; for example, Clint Eastwood yields old west action. Then help Tom Marvolo
Riddle derive his anagram, “I am Lord Voldemort,” using linguistic sieves.
Chapter 4: Decoding American Civil War Ciphers Investigate and crack one of the most
successful military ciphers in history, the Union route cipher. Then help spies on both sides
send and decode secret messages using the zig-zagging rail fence cipher.
Chapter 5: Encoding English Civil War Ciphers Read a message hidden in plain sight by
decoding a null cipher from the English Civil War. Then save the head of Mary, Queen of
Scots, by designing and implementing code to accomplish the more difficult task of writing a
null cipher.
Chapter 6: Writing in Invisible Ink Help a corporate mole betray Sherlock Holmes’s dad
and evade detection with invisible electronic ink. This chapter is based on an episode of the CBS
television show Elementary.
Chapter 7: Breeding Giant Rats with Genetic Algorithms Use genetic algorithms—
inspired by Darwinian evolution—to breed a race of super-rats the size of female bullmastiffs.
Then help James Bond crack a safe with 10 billion possible combinations in the blink of an eye.
Chapter 8: Counting Syllables for Haiku Poetry Teach your computer to count syllables
in English as a prelude to writing Japanese poetry, or haiku, in the next chapter.
Chapter 9: Writing Haiku with Markov Chain Analysis Teach your computer to write
haiku by combining the syllable-counting module from Chapter 8 with Markov chain analysis
and a training corpus of several hundred ancient and modern haiku.
Chapter 10: Are We Alone? Exploring the Fermi Paradox Investigate the absence of
alien radio signals using Drake’s equation, the dimensions of the Milky Way galaxy, and
assumptions about the size of detectable “emissions bubbles.” Learn and use the popular tkinter