DEV Community

Cover image for Learning to code through Nursery Rhymes and Fairy Tales
Sundae Electronics
Sundae Electronics

Posted on • Originally published at

Learning to code through Nursery Rhymes and Fairy Tales

Learn Python through Nursery Rhymes and Fairy Tales is my upcoming book currently available for pre-order on Kickstarter: Link

Learn to Code.

This simple phrase has become quite ubiquitous. Where to start? There are many ways to begin learning to code- online tutorials and lessons, courses, coding bootcamps, as well as the traditional go-to method of reading programming books. I can appreciate the traditional book. I like the continuous structure of a book and the progress I feel after turning each page. I also like being able to open a physical book and easily flip to a topic, especially without seeing ads pop up all over the place like they do on the online programming reference sites.

I’m not alone in these sentiments. Physical books still outsell e-books for many reasons, one of which is the emotional connection readers feel to physical books. The problem I saw with beginner programming books is that they’re written like textbooks…and it’s hard to feel an emotional connection to a textbook! It can also be tedious and boring to read long paragraphs of black and white text.

This is how I first thought of the idea for a colorful picture book that told a story with code, in which real-life situations are described in computer programs. I wanted to create a fun, relatable alternative to the existing textbook-like options for beginner programming books. I was also motivated to create an easy-to-read book that teaches concepts quickly and concisely solely through complete code examples and their explanations. My first book A Day in Code tells a story about a fun day that describes situations with C programs next to full-page illustrations that depict the scenes being described. My recently released book A Day in Code- Python teaches Python basics in the same way. It has a castles and dragons theme, which led me to another idea…

Nursery rhymes and fairy tales written in code

Nursery rhymes and fairy tales have been translated into over a hundred languages, but never a computer programming language…until now. My upcoming book resembles a traditional fairy tale storybook, but with a very modern twist- the nursery rhymes and fairy tales are written as complete Python programs! My intention is that the reader’s instant familiarity and emotional connection to the classic stories will make the Python programs easier to understand and enjoyable to read.

Each nursery rhyme/fairy tale program demonstrates one or more new Python concepts. The code is explained below each program. Each nursery rhyme consists of a single page Python program and the fairy tales are split up into multiple pages each containing a complete Python program. When each program is run on your computer, it outputs the nursery rhyme/fairy tale with print functions.

This code page describes the end of Goldilocks and the Three Bears:
Last code page of Goldilocks

This is the accompanying illustration:

Who knew that classic nursery rhymes and fairy tales from hundreds of years ago are structured in a way that makes them transfer well into good code examples? Translating the stories into Python felt as if they were designed to be written in code. It was fun to view them from a logical standpoint and break them down into code. Goldilocks and the Three Bears turned out to be mostly a series of if/else statements. Other nursery rhymes and fairy tales were well-suited to be “translated” into functions and classes.

Check out my upcoming book Learn Python through Nursery Rhymes and Fairy Tales on Kickstarter: Link

Top comments (0)