This time last year, Audrey wrote a computer program in BASIC.  Someone had loaned us an Apple II computer, and I showed her what computers were like when I was a kid.  I wanted her to write a program, and her mother decided that printing a 10 x 10 multiplication table would be a suitable challenge. So Audrey rose to the task.

This year, I decided to repeat the lesson with Sydney.  However, our two girls are very different in personality and interests, and so we had to choose a different approach.

Audrey was motivated by her interest in history, and in learning how Daddy became a nerd.  Sydney was motivated by attaching a prize to the assignment — a “feather” on her Indian Princess vest.  This would count as one of our father-daughter “crafts”.

I also decided that since I did not have the lead-in of the Apple II computer, I could use any language, and not just BASIC.  I went out on a limb and chose Python.

Sydney followed along as we talked about variables and loops, but she was not nearly as engaged as Audrey had been.  In her defense, I think the idea of line numbers in BASIC is a little easier for a kid to grasp than the indented blocks of Python.  And although formatting the output is easier in Python, all of that punctuation was sure to blow a few fuses in that young mind.

In the end, however, she produced a nice multiplication table.

Here’s her program.

#!/usr/bin/python
import sys

# top line of numbers
print "      " ,
x = 1
while x <= 10:
   print "%3d" % (x) ,
   x = x+1
print ""

# top line of dashes
print "      " ,
x = 1
while x <= 10:
   print "---" ,
   x = x+1
print ""

# ten rows
s = 1
while s <= 10:
   # each row is here
   print "  %2d |" % (s) ,
   x = 1
   while x <= 10:
      print "%3d" % (x*s) ,
      x = x+1
   print ""
   s = s+1
print ""

And here’s what the output looks like:

         1   2   3   4   5   6   7   8   9  10
       --- --- --- --- --- --- --- --- --- ---
   1 |   1   2   3   4   5   6   7   8   9  10
   2 |   2   4   6   8  10  12  14  16  18  20
   3 |   3   6   9  12  15  18  21  24  27  30
   4 |   4   8  12  16  20  24  28  32  36  40
   5 |   5  10  15  20  25  30  35  40  45  50
   6 |   6  12  18  24  30  36  42  48  54  60
   7 |   7  14  21  28  35  42  49  56  63  70
   8 |   8  16  24  32  40  48  56  64  72  80
   9 |   9  18  27  36  45  54  63  72  81  90
  10 |  10  20  30  40  50  60  70  80  90 100

Two days later, Sydney got to show her program to the girls in her Indian Princess tribe.  Needless to say, there were some raised eyebrows coming from some of the dads at that meeting.