Invent Your Own Computer Games with Python

June 13th, 2008

Invent Your Own Computer Games with Python (or IYOCGwP “eye-yawk-gwip”) is a book (hopefully a series of books) that teaches Python game programming for kids in the 9 to 12 year old age range. Instead of teaching principles and concepts, each chapter has a complete example of a game and its source code up front, and then provides explanation for the code.

The main website (for the fancy new second edition) is

http://inventwithpython.com

The book is freely available to copy and distribute for non-commercial purposes under a Creative Commons license. Any feedback or comments would be greatly appreciated.

45 Comments »

  1. Ferruccio Barletta wrote,

    Great Idea! I wish I’d thought of it! ;-)
    It’s been a long time since I was typing in those games from Creative Computing books. The dragon game reminds me of hunt the wumpus.

    Comment on June 18, 2008 @ 11:56 am

  2. Shane Baptista wrote,

    Hey Al,

    I downloaded your python book and I’m loving it so far. I’m gonna use it as an introduction to programming with my 10 year old son.

    I read the about the author and I have good news about your fear of losing brain cells. Neuralgenesis. We grow new brain cells with use. Here is a link to more information. http://web.mac.com/memoryguy/Julian_Keith/Research.html

    Thanks for the book.

    Comment on August 29, 2008 @ 6:59 am

  3. Clint wrote,

    Wow. I remember back in 1987 when I first copied the Dragon World BASIC listing into the TurboC IDE because I wanted to write a game. That was my first introduction into computer programming, and many years later it’s my career. It was a great walk down nostalgia to see Dragon World living again to once again get kids into programming games with Python. Thanks for doing this!

    Comment on August 29, 2008 @ 7:27 am

  4. atik wrote,

    Thanks for grt book

    Comment on September 8, 2008 @ 5:44 pm

  5. Shrinivas wrote,

    Excellent documentation on Python game programming!

    Comment on September 15, 2008 @ 9:35 am

  6. zapman wrote,

    thank you very much for this excellent resource!!

    one thing I noticed: the page numbering isn’t working (pdf version): the table of content always says “page X”, the pages themselves don’t have any number. only minor flaw but maybe you can consider it for the next update.

    thanks again, your book is very valueable to me.

    Comment on September 18, 2008 @ 1:16 am

  7. Jacob wrote,

    This is one of the great tutorials i have being longing to read.great job man. And please where can i get more of such interesting tutorials. And thanks once more.

    Comment on September 23, 2008 @ 10:02 am

  8. Kota Weaver wrote,

    This is awsome! I personally have wanted to learn python for a while now, but did not want to go through the troubles of reading all those boring documentation all over again after already knowing C++ and Java. And since I don’t need to use oop for the way I want to use it (Blender 3D) all I need is this book. Thank you SO much. This will also help all my coder buddies (I was trying to get them to learn C++ until I saw this, and I was not having very high hopes). This will be a good intro for them into the programming world. Thank you once again.

    Comment on September 30, 2008 @ 4:51 pm

  9. shri hari ram.g wrote,

    this is the best python book ,thank u.

    Comment on October 1, 2008 @ 3:33 am

  10. Rajasekaran wrote,

    I searched over the web and found a good resource for game programmers.Thanks for sharing.

    Comment on October 1, 2008 @ 9:46 pm

  11. Anonymous wrote,

    This is a great book! Have you thought about exercises?

    Comment on October 19, 2008 @ 6:47 pm

  12. Thomas wrote,

    Thank you Al!

    I’ve been thinking a lot about how to teach my kids (now 11 and 13) that programming is fun and easy and a good way to learn other stuff on the way. I haven’t found any material on the web yet that would be good enough to do the job, so I have started thinking of doing something myself for JavaScript.

    Now I found your book though and it seems to be just what I wanted. Me and my kids will give it a try this winter. The only problem I can see right now is that our native language isn’t english (I’m from Sweden) but I think we can overcome that as well.

    Comment on November 2, 2008 @ 1:47 pm

  13. VAKE wrote,

    Very interesting book! When can we expect to see book 2?

    Comment on November 3, 2008 @ 7:35 pm

  14. shri hari ram.g wrote,

    its very interesting, right now i am doing GUI programs , can you help me how to compile a .py to .exe

    Comment on November 30, 2008 @ 12:35 am

  15. Raúl wrote,

    Thanks for releasing the book under a Creative Commons license. Sharing knowledge is the way knowledge works.

    A couple of suggestions: talk a bit more about tuples (not only in the Glossary) and use “,” instead of “+” in “print” where possible (“guess.py” has the first example of that. There is no need to concatenate strings using “print” unless you don’t like the default formatting style of “print”).

    Again, thanks for the book.

    Comment on December 11, 2008 @ 11:08 am

  16. Connor wrote,

    will your next book teach the differences of python 3000?

    Comment on December 18, 2008 @ 3:38 pm

  17. ro wrote,

    great resource

    Comment on December 19, 2008 @ 12:20 pm

  18. Sean wrote,

    Perhaps a little early to comment as I am still only part-way through the text but I would like to say that, so far, I have found this a very approachable and helpful resource.
    Thanks for sharing!

    Comment on January 11, 2009 @ 7:58 am

  19. J wrote,

    This is a great book; I’m halfway through it and I created my own Module ( nift ) from what I’ve learned through it.

    Comment on February 8, 2009 @ 11:13 am

  20. Matt wrote,

    Thanks for a great “non-programmer” newbie’s guide! I am finding this guide compliments Dawson’s “Python Programming for Absolute Beginner” book beautifully. I am studying both and am about halfway through each. I am loving Python and it’s all due to Sweigart (and Dawson)! THANKS! And well done!

    Comment on February 15, 2009 @ 4:13 am

  21. azalea wrote,

    Hi,
    I sort of found a ‘bug’ in Chapter 7′s Bagel program.
    When I played with it:

    Guess #10:
    117
    Fermi Fermi Pico
    You ran out of guesses. The answer was 177.

    Intuitively, I think if the answer is 177, 117′s clue should be “Fermi Fermi”, not “Fermi Fermi Pico”. The latter may be misleading in that it indicates the three letters are all correct and one of them is in wrong position, which is not the case.

    So I changed the function getClues into:

    def getClues(guess, secretNum):
    # Returns a string with the pico, fermi, bagels clues to the user.
    if guess == secretNum:
    return ‘You got it!’
    clue = []
    secretNumLeft = list(secretNum)
    for i in range(len(guess)):
    if guess[i] == secretNum[i]:
    clue.append(‘Fermi’)
    secretNumLeft.remove(guess[i])
    elif guess[i] in secretNumLeft:
    clue.append(‘Pico’)
    if len(clue) == 0:
    return ‘Bagels’
    clue.sort()
    return ‘ ‘.join(clue)

    It seems to solve the problem.

    Comment on February 20, 2009 @ 10:19 am

  22. Kalapoika wrote,

    Hey!

    /////Glitch /////
    In the ‘dragon realms’ chapter you were messing about with “chooseCave” and “chosenCave” when I guess there should have been only either one. Gave me a small feeling of ‘OMGWTFFFS’ as a first-timer.
    Thanks

    Comment on February 23, 2009 @ 3:36 pm

  23. Kalapoika wrote,

    Heh sorry.
    Again I’m a newbie. I just understood how it worked with the parameters and all. No problem anymore. Nice guide thank you!

    Comment on February 23, 2009 @ 3:45 pm

  24. spn wrote,

    I just read your first chapter.
    It was great.

    Thank you for sharing your idea

    Comment on March 2, 2009 @ 7:36 pm

  25. Crispin wrote,

    Thank goodness for a jargon-free book. The Python documentation seems to think we’re all programmers looking for a new language to learn. As with the previous commenters, I’ve learnt a lot. Thanks.

    Comment on March 22, 2009 @ 10:26 am

  26. David P. wrote,

    Hello,

    I have download the PDF version of your book.

    Thank you very much!

    Comment on April 4, 2009 @ 9:22 am

  27. Tyler S wrote,

    Hi im 13 and this is an amazing guide. this will help me with my 3d rpg game im making.

    my goal is to spend only 60 hours or 1 hour a day for 60 days

    Comment on May 4, 2009 @ 2:45 pm

  28. Stephen Lark wrote,

    Text is cropped on the left margin starting on page 30 of the PDF of Invent Your Own Computer Games with Python (http://pythonbook.coffeeghost.net/book1/IYOCGwP_book1.pdf)

    Comment on May 30, 2009 @ 7:08 pm

  29. Joshua wrote,

    Hi, I’m reading your book right now. Thank you.

    Comment on July 8, 2009 @ 10:09 am

  30. gaitdocgtor wrote,

    GREAT BOOK GREAT IDEA ON TEACHING PROGRAMMING. HOPE THIS IDEA GETS TRACTION. SOMETIMES GEEKS DO GET WHY NON-GEEKS DO NOT GET IT. MOST PROGRAMMING BOOKS ARE WRITTEN BY GEEKS BUT THEY ARE NOT WRIITEN FOR NON-GEEKS. GEEKS CAN NOT THINK LIKE NON GEEKS. THAT IS WHY THEY ARE GEEKS.

    Comment on July 8, 2009 @ 4:10 pm

  31. joe wrote,

    loved the book, im twenty but i love it still.

    in the book you mentioned a second book, hows that coming along? id love to read that one too, im desperate to program a way to fight the dragons, an rpg, thats something cool. imagine the code id have to write!

    Comment on July 17, 2009 @ 2:11 am

  32. grayger wrote,

    Thank you for free distribution of your great book.

    Comment on August 31, 2009 @ 6:52 am

  33. Steve wrote,

    The following line from Chapter 7 caused me a lot of confusion:

    from Variable scope:
    “Note only that, but when execution is inside the function, we cannot see the variables outside of the function, or variables inside other functions.”

    It seems to say that within a function, it cannot read global variables, but later on you correct that, however if you changed the wording just a little bit I think it might cause less confusion. I think what you mean is, ‘…we cannot modify the variables outside of the function…’

    Comment on October 8, 2009 @ 2:16 pm

  34. Ben wrote,

    Thank you so much for the book. Its great (my friends and I have been trying to learn how to program for a long time, and this tutorial is one of the best!

    Comment on October 24, 2009 @ 8:42 am

  35. Shantanu Banerjee wrote,

    Hi Al,
    Thank you so much for coming up with the idea of writing a book on game development and teaching programming concepts through Python. Leaving aside all the codes of Python and other language syntax in your book, you deserve high praise for the chapter on “Flow Charts”, which I’m sure will build the necessary base required to think logically before writing the first line of code. I’ve myself learned a lot from your book. Thanks once again. Keep this spirit high for ever.

    Comment on February 9, 2010 @ 3:31 am

  36. unleash_the_source! wrote,

    Is there a forum where we can discuss the lessons in the book and ask questions?

    Comment on February 15, 2010 @ 11:14 am

  37. Andy wrote,

    Really a superior piece of work here, Al. This is definitely something that I (a 46 yo non-programmer) want to work through over my forthcoming summer vacation. It looks fun, and the explanations are just spot on.

    You have a real talent for explaining what you are doing with the code and why you are doing it … and that is just the comments sections of your actual programs! The textual narrative expands your well documented scripts, giving a fuller accounting of your thinking in defining and addressing the problems writing the program is intended to solve.

    This is a text that will surely appeal to all programmers who want to cut to the chase on how to resolve those typical problems encountered in creative program writing, and it certainly appeals to me as an interested layperson.

    FWIW, this warrants being converted into a dead-tree version.

    Comment on February 26, 2010 @ 1:03 pm

  38. Jav wrote,

    The best way for reviewing programming. Thank you Al!

    Comment on March 24, 2010 @ 10:32 am

  39. Stuart wrote,

    I have this latest Invent Your Own Computer Games with Python PDF and am looking forward to it’s brilliant content to teach my Software Design class on Python. I’m not too good with this language and before I start teaching them with it, have to ask, why am I getting silly little problems with all the code I have downloaded from your site in the zip file. I get a fault on a line each time I run it, and can’t for the life of me tell what is the problem.

    Other than this, if I can get the code to work, it is going to be a blessing to be able to use such a well put together teaching tool.

    Keep up the good work, and I hope you can help this code dummy very soon so I can use the PDF. :)

    Comment on March 29, 2010 @ 8:04 pm

  40. Jane "Treasure Hunt" McDonell wrote,

    As someone who started programming as a teenager writing computer games as a hobby – thanks for this book. I have passed it on to my son to see if anything wears off on him…

    Comment on May 3, 2010 @ 10:35 am

  41. Treasure Hunt wrote,

    A treasure hunt is one of many different types of games which can have one or more players who try to find hidden articles, locations or places by using a series of clues. Treasure hunt games may be an indoor or outdoor activity. Outdoors they can be played in a garden or the treasure could be located anywhere around the world.

    Comment on August 29, 2011 @ 4:30 am

  42. Werner wrote,

    Thank You for the excellent book.

    I think there is a bug in sonar (ch. 13).
    Line 83: chests.remove([x, y])
    should be replaced by

    while [x,y] in chests:
    chests.remove([x, y])

    because there is the faint possibility that two or more chests may lie at the same place.

    Comment on January 29, 2012 @ 8:42 am

  43. Nilotpal wrote,

    Ur books r simply great.Easy to learn ..looking forward for ur next books

    Comment on February 5, 2012 @ 4:23 am

  44. Werner wrote,

    In Making Games with P&P, I had the following problem:

    I downloaded the media archives flippyimages.zip and starPusherImages.zip (Chapters 9, 10). Trying to unpack, I got error messages:

    Win (7-zip): This is no valid archive.

    Ubuntu (unzip and Gnome File Roller):

    tmp$ unzip flippyimages.zip
    Archive: flippyimages.zip
    End-of-central-directory signature not found. Either this file is not
    a zipfile, or it constitutes one disk of a multi-part archive. In the
    latter case the central directory and zipfile comment will be found on
    the last disk(s) of this archive.
    note: flippyimages.zip may be a plain executable, not an archive
    unzip: cannot find zipfile directory in one of flippyimages.zip or
    flippyimages.zip.zip, and cannot find flippyimages.zip.ZIP, period.

    Simply clicking on the archive link gives me an Error 404 plus
    The requested URL /flippyimages.zip was not found on this server.

    Comment on February 14, 2012 @ 4:49 am

  45. Werner wrote,

    Solution:
    The aforementioned error occurs only with links like
    “http://invpy.com/starPusherImages.zip” as in the online version of the book.
    It must spell
    “http://inventwithpython.com/starpusher.zip”

    Please correct the link in the online version. Thanks

    Comment on February 14, 2012 @ 5:11 am

Leave a comment

(2000 characters left.)

RSS feed for comments on this post. TrackBack URI

Powered by WordPress