
This is how I’ve been teaching my son programming in snatches of spare time scattered over the last few weeks. I’m writing this to keep track of what I did. Hope others get something out of it too!
Setup
Get a Raspberry Pi, monitor, desk, and keyboard.1
The Raspberry Pi comes with a Python IDE called Thonny. Open this up.
To illustrate the REPL, run some fun commands on the prompt at the bottom:
print("hello world"), 2 + 3, "alice" + "bob"
, whatever.Show simple examples of if-else and for loops. Kids get a kick out of silly stuff here.2 If they want to make it do something sillier and/or more complicated, go ahead and explore that if practical. Point out the need for block indentation.
# if-else example
# this doesn't work because a is a string. show how to
# discover this at the REPL, and how to fix it with a
# type conversion.
a = input('type a number: ')
if a == 7:
print('i love that number!')
else:
print('that number is okay i guess')
# for loop example
# it won't look quite right. that's on purpose. can kiddo "fix" it?
for i in range(10):
print('i pooped' + str(i) + 'times')
Turtle
Do some stuff with turtle. Start by showing how to draw a square using
turtle.forward()
andturtle.left()
. Can the kid draw a triangle? Hexagon? Diamond?3How about more complex shapes? A nice transition from the diamond is several diamonds coming out from a common point, like a crystal or flower. Once the diamond is obtained, the crystal can be obtained by cutting and pasting the diamond drawing block repeatedly (plus a turn between each block). Next, you can show how a for loop gets to the same place.
Calculator
At this point, my son wanted to make a calculator. Like “enter an operation” then “enter a number” then “enter another number”. We learned a lot about the little details of Python: type conversion, concatenating string, if-elif-else, reading error messages, and much more.
Why would I do this?
It could seem pointless to teach a kid the details of a specific language they may never use! But I think this is real “liberal arts” learning that is good for everyone. We should all have exposure to the nature of code and programming. It’s a great way to learn things like
how fussy compilers/interpreters are, and the sort of little details that matter to them
the computer is always right, even when it didn’t do what you intended
you should bite the bullet and read error messages even though you think it’s total bullshit that your program didn’t run. error messages are extremely helpful if you build the skill of reading them.
How should I do this?
Do it in a way that’s consistent with the point. We have kids write book reports not to get them to do it exactly the “right way”, or because their book report will add something to the world, but to get them but to activate their independent thinking and initiative. Exact same idea here. If you are an experienced software person, as you may well be if you’re reading this, resist any temptation to “correct” the program to align with how you think it should be. The best program is the one your kid writes, whether it works or not.
Miscellaneous pointers
The Pi can connect to the internet with wi-fi. To keep the kid from wasting time on the infinite Pleasure Island that is the online world… consider either never setting this up, or setting it up then disabling it. We use the Eero router to pause the wi-fi to the RPi specifically. This way we can enable it when needed, e.g. to install packages with pip.
If you ever want to install packages with pip, you’ll need to set up virtual environments with Thonny. Here’s how to do that, apparently.
Or you could maybe just let the kid use your computer, but I didn’t want to feel like my MacBook Pro was at risk every time my kid might want to explore.
As do I when I try new programming features
You might think geometry knowledge is needed for this, and certainly it helps. But part of the fun is to succeed without understanding, by pure trial and error, as (let’s be honest) many professional programmers often do!