Tag Archives: parenting

How to teach your child math using programming (even if you don’t know how)

There are many educational apps, but the power of these apps to teach is limited by the imagination of the designer. A theme of The Curiosity Cycle is that learning should be driven by the imagination and creativity of the child. Programming is an ideal way to do this. Many parents may be drawn to using apps for education because they themselves don’t know how to program or how to use programming as a teaching tool. This blog post will show you how to do both using a free, interactive, and light-weight programming language called Python.

We will focus on using programming to teach math.  In the modern world, math is implemented in programming, much like how hydrogen and oxygen implement the phenomenon of water. This embodiment of math in programming enables your child to poke and prod math like it is a living thing, allowing learning to happen through experimentation.

Your child can also use programming to build a math toolkit that will be useful  later. This toolkit can be used to check homework and do class projects. When your child learns a new algorithm in school, such as long division, he or she can program the algorithm in Python and use it to check intermediate computations. Having access to this toolkit and the ability to expand it will foster a habit of computational thinking. Your child can grow to be like a digital sorcerer casting spells and learning new ones.

Installing and Running Python

To install Python, go to https://www.python.org/download/ and pick the link that corresponds to your computer. I use Python 2.7.7.

For a 32-bit Windows machine:
For a 64-bit Windows machine (most common):
For for Mac OS X 10.6 and later:
For Mac OS X 10.3 through 10.6:

You may have to set the path so Windows knows where to find Python.

Windows 7 and Vista
1. Start -> Computer
2. System properties from the menu up top.
3. Advanced system properties from the menu on the left.
4. Advanced tab -> Environment Variables button on the bottom
5. Under system variables choose “Path”

Windows XP
1. Start -> Control Panel -> System
2. Advanced tab -> Environment Variables button on the bottom
3. Under system variables choose “Path”

Then add “C:Python27″ to that path. Note that there are no spaces, and each entry is separated with a semicolon.

To use Python in Windows, click on the Start (Windows) button and type “cmd” into the little run/search box. When the command prompt comes up, type “python.” You will now be in the Python interpreter and can just start typing commands. (For a Mac, you similarly need to bring up a terminal window.)

If you followed my blog post here and installed Ubuntu, you already have Python installed. Just hit Cntl+Alt+t to bring up a terminal and type ‘python’.

Programming with your child

The interactive nature of Python is a big part of how we can use programming as a teaching tool. It makes it possible to turn learning into a game.  You can play “stump the kid.” You type in a command, and your child tries to guess what the computer will say. Then your child can take a turn at stumping you. To make it even more fun, you can hook up a laptop to a TV and see the action on the big screen.

Basic arithmetic

You can practice basic arithmetic with your child by just typing in math.

Fractions and decimals

When you try division, you may notice an odd thing. 5 / 2 = 2. That’s because Python thinks you want an integer answer (silly). You have to type “from __future__ import division”.

You can show for common fractions that you get decimals. You can quiz your child on what the decimal value will be.

Please Excuse My Dear Aunt Sally

One area where the implementation of math in programming may produce a fun surprise for your child is in the order of operations. When I was in 7th grade, I learned the phrase, “Please Excuse My Dear Aunt Sally.” This phrase was a mnemonic to help us remember what was evaluated first in a math expression: parenthesis, exponents, multiplication, division, addition, and subtraction. In reality, multiplication and division are done left to right (neither has precedence over the other), and addition and subtraction are also done left to right.

You can see this in action. If your child has not studied order of operations yet, he or she will likely say that the answer to 3 + 4  * 2 is 14. Python and Aunt Sally agree that it is 11.

Introducing variables

You can introduce variables, which gets your child started toward algebra.  In Python, a single equal sign ‘=’ is used for an assignment of a value to a variable; a double equal sign ‘==’ is an operator that checks if the two values are the same, as we will see in the next section. Note that your child may get confused between strings and variables. A string, such as ‘dog’, is in quotation marks.

Conditionals and logic

You can use the ‘if’ statement for conditional execution. If a command goes more than one line, just hit return to continue typing. Then, to evaluate, hit return twice.

You can also test for inequality, as shown below.

Now that we are using more syntax, it is a good time to point out that a tutorial of syntax can be found at http://docs.python.org/2/tutorial/.

Errors and flapdoodle

My kids love when the computer says something crazy like when you divide 1 by 0.

You can also use a variable before it has been defined to get some more gobbledegook as output.

These kinds of nonsensical responses may lead your child to the wow-computers-are-stupid stage of learning programming. In this first stage of programming, the  literal mindedness of computers can be a significant obstacle.

The bad news is that you have to tell computers everything you want them to do in excruciating detail, but the good news is that you only have to tell them once.

Modules and functions

You can store your commands in a file so you don’t have to type the same things over and over again. You can also define functions to put in this file. In Python, this file is called a module, and it will end with the suffix “.py”. We will assume that your module is called mymodule.py.

You can create mymodule.py with a text editor, such as Notepad, and save it in the directory where you run Python. (It doesn’t have to be in that directory, but having it there saves us from having to tell Python where it is.)

When you start Python, you can then type “from mymodule import *” at the command prompt.

Here’s an example of a function in python:

Note the indentation. Python uses indentation (a convention is to use 4 spaces) to determine the nesting of statements.

Every time you change mymodule.py, you will need to quit Python (do this by hitting Ctrl-z) and reload it using “from mymodule import *”.

To avoid having to type “from mymodule import *” each time you start Python, you can create another file, we’ll call it startup.py, that only contains “from mymodule import *”. And then you can set a special environment variable to run that startup module each time Python is loaded. To do this, set the environment variable PYTHONSTARTUP to point to your startup file (instructions for Windows are given below).

Windows 7 and Vista
1. Start -> Computer
2. System properties from the menu up top.
3. Advanced system properties from the menu on the left.
4. Advanced tab -> Environment Variables button on the bottom
5. Under system variables click “New”

Windows XP
1. Start -> Control Panel -> System
2. Advanced tab -> Environment Variables button on the bottom
3. Under system variables click “New”

Coming in Future posts

In future posts, I will discuss more about functions. We will also talk about loops so your child can multiply a number by 10 until it is so big it covers the whole screen. From there, we can introduce all kinds of concepts
such as factoring, identifying prime numbers, finding the greatest common denominator, and sorting.

We will also look at recursive functions (functions that call themselves) such as the one below.

If you have any trouble getting set up, feel free to contact me at jonathanwilliammugan@gmail.com.

Computers all the way down: a free virtual machine for your child

The Curiosity Cycle emphasizes that tool use develops the mind. Tools are even better when they are your own. In this blog post, I’ll explain how to create a computer within a computer for your child.


This computer within a computer is called a virtual machine. Your real computer simulates every action of the virtual machine, so it appears just like the computer you normally run. Well, actually, the virtual machine described in this blog post will be different from your normal computer if that computer is a PC or Mac. This virtual computer will run an operating system called Ubuntu.

Ubuntu is free and open source. Open source means that you can look at the programming code for how it works. You can’t do this with Windows. With Windows, even forensic investigators have to guess at how the system works. Using Ubuntu is analogous to having an old car where you can look under the hood and see the moving parts.

Your child will love having a computer of his or her own. My oldest son really likes that his little brother can’t use his computer, and both he and his brother love customizing the look of their screens and setting their bookmarks. In addition, restricting your kids’ internet searches for ninja Pokemon badger-cats to be within the virtual machine helps to protect your main computer from rootkits and other malware.

Installing the computer within a computer takes three steps. These steps take some time, but the installation is like making a cake from a box–you can go off and do other things while you are waiting for it to bake. Note that for the virtual machine to be zippy and responsive, you need a fairly new computer (any computer purchased within the last two years or so should be fine).

Step 1: download and install the free VMware player from https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/4_0
(you may have to restart your computer, ugh).

Step 2: download the free Ubuntu operating system from http://www.ubuntu.com/download/desktop
(this make take a while).

Step 3: follow the instructions at
You are pretty much done once you get to  “Installing VMware tools” because you can just follow the onscreen prompt to install VMware tools for Linux (Ubuntu is a flavor of Linux). At some point, VMware will ask you about an update to the paid VMware workstation; you can click “skip this update” or “skip this version.”

ImageOnce the install process is done, you are ready to go. You will probably need to install Adobe Flash at some point. Luckily, Ubuntu has a built-in app store called the Ubuntu Software Center, which has a version of Flash. You can go to the Software Center by clicking on it on the side, and then you search for flashplugin-installer.

You can also use this app store to install free games. My kids have fun looking through the games. As another activity, your child can create documents because Ubuntu comes with free software that is similar to Microsoft Office.

Interestingly, the whole virtual machine can be saved as a big file and moved to a different computer. On Windows 7 machines, the virtual machines are stored in C:\Users\<your profile name>\My Documents\Virtual Machines. We think of a computer as a thing, but it is really just a  collection of information running (eventually) on hardware.