Python for Kids

Code Snippets from the Book

Gorilla Here's some of the longer code samples used in "Python for Kids". If you're having trouble getting any of the code in the book to work, why not download it from here and compare with what you've typed - it might help you figure out where you've gone wrong. If you're really struggling... you can always get in contact.

(Update: the stick figure zip file link was broken - it's now been fixed)

Chapter 2

Magic coins example.

Chapter 3

Favourite sports.
Furniture placeholder.
A list of lists.
A letter from Malcolm Dithering
Escaping quotes
The Wizard List

Chapter 4

The turtle draws a square.
The turtle draws two parallel lines.

Chapter 5

If statements
Conditions in if-statements.
Else-if (elif) statements.
Strings and numbers.

Chapter 6

Five Hellos.
Huge hairy pants (example 1).
Huge hairy pants (example 2).
Magic coins (example 2).
A while-loop with multiple conditions.
Looping through the wizard list.

Chapter 7

A function to calculate your savings.
Building a spaceship.
Test function (example 1).
Test function (example 2).
Your age function.

Chapter 8

Giraffes (example 1).
Giraffes (example 2).
Three turtles.

Chapter 9

Using the abs (absolute) function.
Using the exec (execute) function.
Using the len (length) function.
Using the max and min functions.
Using the range function.
Using the sum function.
Opening a file.
Writing to a file.

Chapter 10

Copying objects (example 1).
Copying objects (example 2).
Guess a random number.
Random desserts.
Using the time module.
Using pickle to save information.
Using pickle to load information.

Chapter 11

Drawing an eight point star.
Drawing a many point star.
Drawing a spiral star.
Drawing a nine point star.
Drawing a car.
Drawing a yellow circle.
Drawing a filled green circle.
Drawing a dark-green circle.
Drawing squares using a function.
Drawing filled and unfilled squares.
Drawing stars using a function.

Chapter 12

Clickable button (example 1).
Clickable button (example 2).
Drawing a diagonal line.
Drawing a square.
Drawing a horizontal rectangle.
Drawing a vertical rectangle.
Drawing random rectangles.
Drawing coloured rectangles.
Using the color chooser.
Drawing arcs.
Drawing polygons.
Drawing text.
Drawing images.
Basic animation (example 1).
Basic animation (example 2).
Using events (example 1).
Using events (example 2).
Using the move function.
Using the itemconfig function.

Chapter 13

Bounce (example 1) - this one doesn't do anything when it's run.
Bounce (example 2) - stationary ball.
Bounce (example 3) - ball moving upwards.
Bounce (example 4) - ball moving up and down.
Bounce (example 5) - ball moving around the screen.

Chapter 14

Bounce (example 6) - adding the paddle.
Bounce (example 7) - moving paddle.
Bounce (example 8) - bouncing the ball when it hits the paddle.
Bounce (example 9) - ending the game when the ball hits the floor.

Chapter 15

Transparent Image - 27 by 30 pixels. transparent-image.gif
6 Stick Figure Images - left and right.
3 Platform images.
2 Door images.
Background image. background.gif

Chapter 16

Stickman Game, version 1 - displaying the background.
Stickman Game, version 2 - adding the within functions.
Stickman Game, version 3 - adding the platform.
Stickman Game, version 4 - adding lots of platforms.

Chapter 17

Stick figure sprite class.
Stickman Game, version 5 - adding the stick figure.

Chapter 18

Stickman Game, version 6 - animating the stick figure.
Stickman Game, version 6 - adding the door sprite.


Pygame2 example.
Hello World Java example.
Hello World C example. helloworld.c
Hello World C++ example. helloworld.cpp
Hello World C# example. helloworld.cs
Hello World PHP example. helloworld.php
Hello World Objective-C example. helloworld.m
Hello World Perl example.
Hello World Ruby example. helloworld.rb
Hello World Javascript example. helloworld.js
Hello World Javascript Browser example. helloworld-js.html