
Learning to Program with Python.
Copyright © 2007. All Rights Reserved.
“Snake Wrangling for Kids” is a printable electronic book, for children 8 years and older, who would like to learn computer programming. It covers the very basics of programming, and uses the Python programming language to teach the concepts.
There are 3 different versions of the book (one for Mac, one for Linux and one for Windows), and the printable 1.4MB PDFs can be downloaded from the following links for free (zipped size is 1MB):
SWFK - Linux Edition
SWFK - Mac Edition
SWFK - Windows Edition
Printed versions can be obtained from Lulu via the following links:
SWFK - Linux (Printed Edition)
SWFK - Mac (Printed Edition)
SWFK - Windows (Printed Edition)
Please note: this is a self-edited (obviously unpublished) manuscript (with help from feedback from the Python community), and as such may not be quite as polished as I would like. Feedback is welcome, and I’ll update the book whenever necessary. If your kids are having trouble understanding something, please let me know, and I’ll use the feedback to hopefully make improvements.
All updates will be announced here (or the feed subscription is http://www.briggs.net.nz/log/feed).
The original combined version (including all 3 operating systems) of the book can still be found here.

These works are licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License.

I’m very interested in your book. I’m a teacher, and I like to teach the programming basics to children in my school.
I am very interested in Python Language
Hello everybody
a fantastic book for beginners - Lovely lay out and worth reading
I am interested in python
I want to know more about Python. So please help me
Try reading the book…
try this book for understanding python
Create a Google code project to host the source format for the book (I hope it’s reStructuredText or DocBook) and you’ll get some editors ..
I was *just* about to start teaching my nine year old Python. This book will come in handy.. Thanks! I’ll let you know how it goes.
Thanks for this, I plan to teach my kids to program and this is going to be a great help.
Nice book
i have kids too and i started teaching them python some 2 or three 3 months ago. Since the only book i could find was for ages 12 and up, i started writing my own as well.
In German that is. I could mail you one draft version if you are interested. You might not understand it but i guess the structure is obvious to understand.
Perhaps we could cooperate somehow ?
Outline the general structure, agree on a timeline and start writing the chapters ?
Should not be to difficult to find people helping in translation.
English, german should at least not be much of a problem for me
I like the illustrations of the book.
Something i would recommend however (i included that in my book after feedback from my kids): You need more excercices with solutions.
Ask the kids to do something which requires them to apply the taught material. Then present one solution in an appendix.
PS: Just an obvious mistake I came upon in 2 minutes rereading:
“Which is $5 + $30 multiplied by 52 weeks in a year. Of course, we’re smart, and we know that 5 + 30 is 35, so
the equation is really:
35 × 50″ <- should be 52
Hi, thanks for writing this book. There don’t seem to be many such kid-focused books available (on Python or any other computer language).
One suggestion is to explain why on page 15 the answer to 8 * 3.57 is 28.5999999999999 instead of 28.56.
Maybe you should use integer multiplication to start out with, to avoid having to worry about this. Such distractions and confusions may be enough to put kids off completely.
On the other hand, I suppose kids who are scared off by this aren’t really cut out for programming computers and would be better off putting the book down and doing something else
On page 68 it looks like you have your x and y axes reversed on illustration 31.
I have read through to page 21.
Looks very nice!
One thing I suggest you consider changing: the use of the word “variable”, and the notion of box to put things in.
This is fine for memory-location-based languages such as C, but it is misleading for Python.
Python works with values and names.
a=3 binds the name “a” to the value 3.
We can have more than one name for a given value, and that can cause great confusion if we have this “variable” idea.
Thanks for the book, it’s very useful.
I second what “8. Jean Jordaan” said: put the source out there, and you’ll get lots of edits and translations.
Also, the point made by “14. JSB” is essential. See this doc by David Goodger, made clear with images:
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables
Some comments:
You use the word equation for some stuff that I believe to be just expressions, may not be very important. But could confuse a child who knows what an equation is.
There’s an indexing error on page 22, t[1] should return 2 rather than 1.
Maybe you should try to use doctest or similar on all source code in the book, that way you can be sure there are no errors. I think Dive Into Python did something like that.
I’m not sure about the tradition in English writing. But in Swedish writing it’s recommended to write out numbers below ten. Obviously that doesn’t count for things referring to code. But maybe 4th should be written as fourth?
Jean: good idea regarding the google code project. Thanks very much. No, the book is not in a particularly useful format unfortunately (OpenOffice doc). I intend to rewrite in LaTex at some point, but that’s a low priority job.
Kerim: thanks for the correction.
Lou: I agree regarding computing books focussed at kids. There are a few out there, but nothing I thought was particularly useful. The problem for publishers, I guess, is that the potential market is so small — which doesn’t make publication economically viable. My original intention was to get SWFK published, but the reaction from the first publisher I approached was pretty unenthusiastic. Which goes some way to explaining the problem.
By the way, I’ve fixed the illustration, and I think you’re right about the example on Page 15. It definitely needs more explaining. v0.5 of the book has a bit more info, which hopefully helps.
JSB and Nicola: I realise there’s a fundamental disconnect in the idea of using the term “variable”, but the distinction between store-by-value and store-by-reference is a rather subtle one to understand when you’re just starting programming. There are a couple of places in the book where I decided that to explain the way Python *really* works would potentially cause more confusion than not. That said, perhaps it’s worth revisiting that explanation. I’ll definitely mull it over.
Sebastian: Regarding expression versus equation, the trouble I see is that I’m not sure kids at that age are aware of the difference… or even know what an “expression” is. They will probably have a concept of “equation” though. I could be wrong, of course.
I did manually test all the examples as I wrote the book, however while editing I did change some around and then (obviously) missed some. I’ve fixed that example already (someone else noticed as well), but hadn’t gotten around to uploading the newest version.
Congrats, great job.
Tiny typo on page 44 (version 0.5):
>>> my_savings = savings(20, 10, 5)
>>> print my_savings
25
(last underscore missing in text)
Two other comments, I suppose:
1. Might want to point at http://docs.python.org/tut/tut.html
2. Python’s a great language to at least mention OO.
Thanks Brian. Fixed the underscore.
In regard to OO, I considered it, but decided that getting into a discussion about object oriented programming was a little further than I wanted to go… at least in a book for beginners.
Perhaps the publisher you approached is just shortsighted. Maybe try some other publishers? There are plenty of other good children’s books (e.g. Dr. Seuss) that were initially rejected many times. I think the book would be particularly useful to the growing community of home-schoolers here in the USA. I have tried to get my son interested (he is home-schooled), we’ll see what happens…
Not shortsighted, I think. Just not convinced in the economic feasibility.
In terms of trying other publishers, it comes down to the fact that I’m being extremely lazy. To go through the conventional publishing submission process is a pain. To post on my website is a click or two.
Hi again,
i read some more of the book.
By now i think a bit differently about it. I still like the idea but I think it has mainly ONE or TWO flaws.
1) The level is too high for 8 year olds. You don’t spend enough time to explain things via images (especially variables) or in detail and your speed is way to fast. This shows at around page 19/20/21 for example. Until around page 19 one can follow although already one looses a bit the deep understanding of WHY it is important to learn this stuff (this is related to mistake 2 see below). But then when you start with lists, tuples and suddenly change to graphics again it becomes very frustrating for kids to follow that. You kind of “throw out” the facts but there is no red line as to WHY this matters. The main reason apart of it being explained too fast (actually you more or less just state it but dont explain anything) is:
2) Not enough practical (real) application of knowledge.
You see, my kids often ask me “what can i do with that?” when i explain them something.
So when i say that you can do tricks with strings (I admit i do the same mistak in my book) they dont come up themselves and say “cool i can do this and that with it”. At least not when they are 8 years old. You need more practical parts, some that show things and their solutions, some that ask for a (simple) solution from the kids using the knowledge they just got from the text. It is important to keep them involved using tasks.
Perhaps an example (sorry if my text is so long):
I explained the mathematical operations with a list similar to your table. Then however i let them calculate certain terms and check the results. On purpose i make some that will fail. They will SEE that 10.0/7 is not the same as 10/7 or that “Test’ doesn’t work.
And AFTERWARDS i explain why. (btw. thanks for the rounding example.. i will incorporate that in my book)
Anyway … keep it up.
Kerim
Thanks for making this book, I love the buildup of the examples. Good stuff!
Kerim: the jump from the basics (lists, tuples, etc) to graphics (and back again), was basically because I had a number of suggestions to move the graphics chapter earlier, to keep kids enthused. It’s not possible to move it too early, without losing some of the background information, hence there’s a bit of a jump from one subject to the next. We’ll have to agree to disagree on that one because I don’t believe it’s necessarily frustrating.
Thanks for the book.
You said:
> I realise there’s a fundamental disconnect in the idea of using the term “variable”, but the distinction between store-by-value and store-by-reference is a rather subtle one to understand when you’re just starting programming.
There’s no need to explain store-by-value versus store-by-reference, but it’s misleading and unnecessary to give the student the false explanation that Python stores objects “in” variables.
Far better would be to explain in terms of, say, “attaching a cardboard tag (or a sticky-note) to the object, and writing a new name on it so it can be talked about later in the program”.
This allows later concepts to simply build on that analogy and remain correct: objects can have many different sticky-notes attached and they’re still the same object; sometimes objects can have *no* sticky-note attached and be used immediately; re-using the same name just switches that sticky-note to a different object, leaving the existing object with whatever other sticky-notes it still has on it; and so on.
That way, the student would have a simple mental model of the process of assignment, but one that actually matches the way Python works and won’t need to be un-learned later.
I’ve already started making changes to that section anyway (being convinced by prior arguments). I’ve probably taken the “easy way out” by not differentiating the way Python handles ‘variables’ compared with other languages.
On variables, names and values:
One approach is the balloon analogy:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/fb87d3aca322f869/a47479cda0ae92a6#a47479cda0ae92a6
and
http://groups.google.com/group/comp.lang.python/browse_frm/thread/fb87d3aca322f869/a47479cda0ae92a6#a47479cda0ae92a6
If the intent is to explain programming (and how computer work) by using Python, then there is a case for introducing a way of thinking that is “closer to the metal”, such as “a variable is a named box that can contain a value”. The names and values view is much more abstract, but is accurate for Python and other high-level languages of the same kind.
I like the balloon analogy a lot. Brilliant way to explain how garbage collection works. That part is probably a bit advanced for the level I’m aiming at, but I appreciate the info.
I noticed that they use python a lot in the one-laptop-per-child project. It seems that your book could be very useful as part of that project. A big win for OLPC would be teaching kids to program.
See the following discussion if interested:
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/a5b3e3facd134c21?hl=en
I thought about adding examples for the OLPC originally, but it only supports GTK (AFAIK). The OS image I tried didn’t have turtle or Tkinter support — thus the examples would have to be significantly different from the Linux/Windows/Mac examples.
Congrats Jason,
This is an excellent idea and I am just waiting for my son to grow up a bit more before I can start teaching him with this book’s help.
As I was reading through the first few pages, I found it distracting and a bit annoying to have to select the linux section while skipping the windows and mac sections. I am sure this will be less important later in the book, but still wonder if it might not be better to have 3 versions of the book so that those who only use a Linux system dont have to have all the stuff of how to set Python up on Windows or Mac.
I did think about releasing different versions, but there’s only a couple of places where I need to differentiate between the operating systems, so decided it was a bit too much effort.
Great Book!.
Working through it with my 12 year old son at the moment.
If you care to give me your email address, I’ll send you any typos I find (you could create a gmail addy specifically for this so that you will have all corrections in one place)
I’m reading version swfk0.5.
So far, first found is Page 42 line 16:
“
Sorry, your comment system stripped out everything after my opening quotes.
the typo
And stripped it out again, by the look of it.
See the contact page for my email address if that’s easier…
Thanks for taking the time to write this and put it on the web. Are you perhaps interested in a Hebrew translation? I’m not sure how much work it would be, but I might have a go at it…
Hi Ami
Hebrew translation would be welcome. As I said to someone who was interested in doing a Portuguese translation, possibly best to wait until I’ve done a bit more tidying up… which I’ve almost finished doing anyway.
If you’d like to have a go, only restriction is to release under the same conditions I do (i.e. for free, not commercially). And if you want me to host it here, that’d be fine as well.
J
Yeah, sure, it goes without saying to keep the original license in any translation. It would never occur to me to change anything relating to license, authorship, etc.
Any chance of your posting the OO Doc source, then? I see you’re planning on changing to LaTeX, but since I haven’t a clue how to compile LaTeX Hebrew, the current OO Doc source would be even more convenient.
If somehow made available, I’ll be happy to send incremental translations. It’s very nice of you to offer hosting also, and it would be nice having all different versions in one place in any case.
Thanks!
The problem with the OO Doc source is that it’s already out-of-date with the changes I’ve made for the LaTeX version. Can you email me some Hebrew text (see the Contact page), and I’ll figure out how hard it’s going to be to do it with LaTeX…?
Nicely done. My suggestion is to the discussion of the format of the document. I know that LaTeX is nice because it is designed for books (I wrote my these in it :). However if you’re going to keep this free I would suggest a markup language instead, perhaps something like reStructuredText. That way you could produce pdfs and html versions very easily as well as writing scripts to switch between os versions (mac, win, linux).
The trouble with reStructuredText (which I briefly considered) is that the final output quality (at least to PDF) is nowhere near as good as LaTeX.
Second problem… I’ve already completed the LaTeX conversion…
LaTeX is better quality true, it’s what it is designed for. However, the barrier to entry of LaTeX is higher. I guess it will depend on what you intend to do with this project really.
Given that LaTeX is text based you can probably still do the code switch though.
Another thought on publishing, Have you considered the self publish sites? Don’t know how they rate but the idea has appealed to me in the past.
Not that keen on self-publishing to be honest — other than posting a PDF here for people to download and print themselves.
Nice work!!!!!!!!
Thanks!
Thanks!
I am 11 and I think this is a nice book. It has a friendly feel to it. I haven’t finished it because I can’t figure out how to memorize stuff and still keep on reading (I read fast)(also testing some of the code). I tried to do the C language, but Python so far seems to be more logical and this book sort of encourages me to comprehend the language more. -Still sort of scary trying to make sure I have it melted into my brain though, I just don’t want to go to the Python shell and think in my mind ‘Uh oh… What do I do again?’. But I think this is a nice friendly book (despite it acting like a snake and asking for a tooth, =]).
–Caleb
Hi Caleb. Thanks for the message.
If there’s anything you find too hard to understand, or doesn’t make sense, please post a message here, to let me know. The good thing about this being an e-book is that I can easily change it.
\usepackage[pdftex]{hyperref}
gets you pdf from LaTeX, and there’s also one for LaTeX2HTML, though I’ve never used it.
Excellent book and much better now that it is in three versions (as the less able kids were confused by the multi instructions). I have a group of 11 year olds working their way through it on their own. I just showed them how to download it, save to their own folder and now they are programming away in Python. Thanks, Jason!
Oh, another suggestion I have if you want to expand it is to give more variations on the exercises. It will help them remember them.
I’ve been getting the kids to try variations such as getting the computer to print out multiples of their strings. They get a kick out of seeing how fast the computer can print their name out 10 000 times, lol.
I very much like this book.
Very easy going on the eyes… im 20 and started python programming about a year ago…. would have loved to started with this book.
Keep it up!
Thank you.
Very nice book, i like it.
I would like to translate it into Hungarian. Or at least to begin.
(My son only reads Hungarian yet… )
Is it possible to access the source of the book?
Many thanks,
Absolutely. The source is in LaTeX form and if you know how to use Mercurial, you can download the source from here:
http://www.briggs.net.nz/hg/swfk
There’s also a web interface here:
http://www.briggs.net.nz/hg/swfk/file/tip
Thanks, I now have the source.
I cloned the mercurial, then tried to build.
I’am afraid some files are missing from the SCM:
*-edition.eps
and cover.eps
I can live without them starting to translate, but someone might be interested in getting them.
I’ve added the *-edition images, but the cover is too large to include. I recommend you create an empty eps file for the purpose.
I am a kid who got this site from another friend. I have tried to learn python 3 TIMES! It just made me either fall asleep give up or the tutorial wasn’t even finished. This is complete and keeps me awake with the interesting facts you put in every once in a while.
I havent finished but i plan on doing so. Thank you for finally making a good python tutorial.
Good luck finishing it!
I don’t get the How to ask a question chapter, i put exactly what you have on there and it comes out as an error. ???
Which example and what’s the error?
Ok figured it out i didn’t want to look to stupid so i went back and tried really hard to figure out what i was doing wrong and I wasn’t indenting. THx and sorry.
No problem at all.
I was wondering is there a site that teaches you how to make games with python? Or this program is for kids what do most kids like games so you could do another tutorial about games but make it so that you can’t do the 2nd tutorial until you’ve done the first.
I’d check out the pygame tutorials:
http://www.pygame.org/wiki/tutorials
Plus there’s a book about games dev with pygame, linked on that site…
Thought about self-publishing this on something like Lulu.com? My son’s going through the PDF, but we ended up printing out chapters to hold while he goes through the exercises.
Very good book!
I had briefly thought about it, but there’s a reasonable amount of effort (I think) converting it to a format suitable for Lulu. While I’ve had a considerable number of downloads (quite gratifying number ,actually), I’m not sure there’s a market for a printed version — especially not now someone has published a programming book for kids on Amazon…
Thank you very much!
One of my plans (for the summer) is to start learning python as a good friend suggested it would be a good language to learn (I was discussing the possibility of learning C++ over the summer with him) I haven’t yet found that many books in the library that would help a beginner (as I really need to understand the concepts) but having had a quick read through the pdf, which I will be printing in colour, I think I have found the ultimate guide for a newbie!
p/s: I’m in my early 20s.
You’ve discovered one of the big problems with a (free) electronic book — it’s not going to be found in the local library…
Thank you for this book. I am teaching myself Python and am thinking of teaching my own 10 year old as well as a class of 11 year old’s. This will be an excellent resource!
In 5 minutes with this book I have learnt more about Python than I have in 3 hours playing on my own.
Thanks!
Glad you’re finding it useful.