Teaching Programming to a 9-year-old: Part 1

Vir Gandhi
10 min readOct 17, 2021

I had been thinking a blog or a article since some time, but somehow couldn’t think a good topic to write on.
Initially, I wanted to write something about coding, kind of like “how-to”s for many things while doing code development. But I realized whatever I could write is already probably already there on the internet and more likely even explained better than what I could. But anyway because of that, I couldn’t start writing anything..
But one fortunate day, a thought came to my mind that since I’m already surrounded by children why not write about how to teach programming to a child. If no one else, I will at least be able to teach one child. It was a win-win, I could start writing a blog and one child will learn programming and probably on the way, many some other people can use it to teach other children.

Enough of the story, let’s start..

Background about the child —

Let’s call her Emma. She’s 9 years old and in 3rd grade in Primary School. She’s from Japan and she goes a Japanese public school.

Except for using computer or mobile for playing games, she has almost no understanding of what we can do with a computer or how programming works etc.
But the important thing was there. She had interest and motivation to learn more about computers and programming.

Session 1 (1hr):

What I planned:
- Ask her what does she think about Computer?
- Ask her what does she understand by the word programming?
- Tell her a little bit about how Computer is nothing but a box which can follow instructions.
- Tell her about language that the computer understand, basically 0s and 1s.
1. What are switches?
2. How can we express switches using a single 0 or 1.
3. Give a little more complex examples of switches
4. Tell her about ASCII codes -> not ASCII directly but how any character is understood by computer

How it went:
She came along with father who was also curious how the session will proceed and along the way maybe help me explain few things to her since he knows to communicate ideas better to his child.

For both what is Computer or what is programming, she basically had no idea.

So I told her that Computer is nothing but a box which can follow instructions.

And obviously it didn’t make sense to her.. From an adult’s point of view, maybe it’s pretty easy to make sense of that, but the child’s perspective it was difficult to understand what I meant by instructions or even why Computer is a “box”?

So, the first thing I had to explain what is a instructions. You can give any example that a child might use it in daily life. Something like “switch on the AC”, “switch on the light”, “Alexa, play some music” etc.

I actually I did not expect that it would be difficult to explain what a instructions exactly is.
But somehow we were move on from that onto the next topic. (probably the most complex part of first session).

The next step was to teach her what are switches and how to represent them using 0s and 1s.

We started with one single instruction:

(I1 — Switch to operate the light.)
Since there are only 2 states, for each state of switch I explained that you can represent using 0 and 1. When it’s ON, we can call 1 and when it’s OFF we can call it 0 .

One thing I could have done better was to explain the substitution of ON with 1 and OFF with 0 .

I wouldn’t say the concept was still very clear, but anyway I moved on with the hope that if I explain about more switches, it will probably makes sense to her.

So, we increased the switches to 3.

(I1 — Switch to operate the light.)
(I2 — Switch to operate the AC.)
(I3 — Switch to start/stop the song.)

And the same as one switch, now that since there are 3 switches we need 3 0s and 1s to identify their states.

At this point, it would probably be better if you show all the combinations of switches to explain the point clearly.

And then since this part was clear and we can’t go too deep into more about switches, we moved on to learning what any program basically does.

Programs help you give instruction to computer by converting “human language” into “computer language” and vice-versa.

And I wanted to show just a little of what human language is converted to in computer language, so we looked a little at ASCII Tables.

This could be fun part. You can ask the child to convert their name into numbers and vice versa using ASCII table.

I think the last part connected a lot of what we did in the session. It made her help clear how computer understands human language, and how programs help do that.

Session 2 (~50 mins):

Yay! We are on week #2.

What I planned:
- My next plan was to teach her that computer in general have no self-thinking. If you don’t tell it something, it won’t be able to figure out by itself.
- The plan was play a simple game to understand how to give instruction to the computer.
The game:
- I drew 2 small adjoining circle on a yellow piece of paper with one of it’s corner folded. (Something like this 👇)

- And now the child has to write instructions for drawing those circles at the exact position on a yellow paper from a bundle of origami papers.
- Once she writes it, I will try to follow the instructions as it is without any thinking and see if it works.
- My goal is to find as many mistakes as possible. Say she wrote that “Draw a circle”, and she didn’t specify where to draw the circle, I will draw it at the opposite end of the paper.
- And her goal is to write the instructions with as many detail as possible so that I can’t find any mistake and the final result is the exact copy of the target image.

How it went:
- We started with a example of how to make a cup of coffee (I think most of the children of 9–10 yrs will know. If not, you can start with any simple instruction that the child know.
- She gave the method something like:

  • Boil the water
  • Pour it through the coffee filter

- We explained that since you’re giving that instruction to a human so it will know that how to boil the water or pour the boiling water into a cup and not somewhere else like on a floor etc.
- For computer to understand the instruction, you have to mention each and every detail so that there’s no unexpected result.

Once that was clear, we started the game that I planned.
Her father also joined the game to write the detail instructions.

As expected, the first try was false.

She missed where to draw the circle or whether the 2 circles be adjacent or not and few more.

I found the mistake and she revised.

I again found the mistake and she revised again.

And finally, she was able to write a detailed instruction to achieve the target image.

(you can make it a fun game, rather than making it a strict lesson)

And with this, she understood that the computer is a dumb box and cant do anything if the proper instruction is not provided. And also she got a idea of how to think in detail.

Session 3 (~50 mins):

Now’s the time to do some hands-on.

What I planned:

There’s a really good site to start learning programming for beginners/kids called Scratch (Side Note: If you know LOGO, this is like that but just a little more interactive and more easier to learn)

I created 6 different problems in which we will need to different concepts for complete them:

  • Jump on click (<- just a simple basic problem)
  • Say something on click flag (<- still basic but with more conditions)
  • Go 3 steps ahead and come back. (<- learn to use repeat and forever condition)
  • When touching this color, go to some place or say I’m fine (if-else condition)
  • On 3 say something and wait, else increase the number by 1 (<- learn to use variables + little bit of math ( mod , increment operator) + if-else condition)
  • Follow a path (Learn to use more characters + if-else condition)

Tbh, to be able to complete all 6 in one session were impossible to begin with.

How it went:

I overestimated my teaching capabilities to a 9 year old.

You can start with watching some tutorial video to get an idea of what Scratch is.

The Scratch looks something like this:

What we can do:

  1. First of all there’s a cat character on the right hand side. We can make it do different things by giving different instructions/commands. You can make it move, jump, say something etc.
  2. If you see on the left side, we have a list of predefined instructions that we can give to the cat.
  3. The middle empty area for creating a list of instructions to give to the cat.
    We can create a number of combinations of instructions using the list provided on the left side. And since it’s just drag-and-drop, so even children can do it quite easily.

Anyways after that, we started with a little basic stuff.

  • Jump on click

This was pretty easy as you might expect. But let the child play around with screen to get used to the website operations.

  • Say something on click flag

Same as before, it’s a pretty simple instruction but it will increase the conditions for the cat to do something.

  • Go n steps ahead and come back

So let the child try break the problem first into 2 parts. One, moving forward and two, going back.

The first one — going forward:

This is was quite simple.

The second one — going back:

This was tricky, considering there’s no way to flip the cat around vertical axis for it to move backward.

There are a couple of ways, but what I went with was explaining how to use x-direction on a graph.

You don’t need to explain the whole graph and co-ordinate system but just what a line represent is enough.

But if you don’t want to go this way, there are other ways as well. (e.g. rotate the cat, change the direction of the cat etc..)

This was kinda difficult, to be honest.

We ran out of time pretty quickly and we decided to finish the session then.

Session 4 (~50 mins):

What I planned:

This time there was not much of plan except for improving her understanding of what she learned the last time and try to come the problem which she couldn’t complete the last time (i.e. make cat say something on every 3rd step)

I decided to break the problem into 4 parts:

  1. What is a variable?
  2. What is the mod function?
  3. What is `==` function?
  4. What does `if(a==b)` mean?

If a person understands all the above 4, one can solve that problem.

How it went:

The day before the session, she was free and wanted to get some head start so she came by to practice mod function.
Since she can do divide, explaining mod was a little simpler. (mod is basically the remainder when you do a divide by b )

She was given a lot of problems to do division and find the remainder.

Once she did them, she was given problems to find just the remainder (basically mod).

Different division and remainder problems

The next day(the actual session day):

First, we just revised what mod meant.

Secondly, I wanted to explain her what a variable was.

A simple explanation for a variable is that it is a placeholder . Whatever you want write, you can use variable instead of the actual value.

“variable could be anything and everything.”

Then we tried a simple problem where the cat says it’s step number every time it makes a step.

variable = 0;
forever {
move 1 step
change variable value by +1
say `variable`
}

The above thing will time. Do it slowly and patiently..

On to the next step what is `==`.

This was actually quite straightforward, unlike what I expected.

Instead of explaining the symbol, I just had to explain what is true and what is false .

If you write variable == 4 and if variable is equal to 4, then it’s true, otherwise false.

Same way you can multiple examples.

You can combine explaining if(condition) along with that. (<- That’s what I did.)

And then you can proceed to do some simple example like:

variable = 0;
if(variable == 0){
say 'meow'
} else {
say 'anything'
}

On the last step,

Now that she knows almost all the things required to solve the problem.

First thing for this would be to explain to when a mod b will be zero.

First, I let her do a lot a mod 3 and then a mod 5 and the a mod 4 .

And then try to explain her the pattern that for a mod 3 every 3rd answer will be zero.

For a mod 5every 5th answer will be zero.

For a mod 4every 4th answer will be zero.

Once she understands the pattern, she can understand that if you want to do something every nth time, you can do it using a mod n .

Now try to combine all the steps into one final solution.

It would be better to extend the solution that you already did in the current session.

variable = 0;
forever {
move 1 step
if(variable%3 == 0){
say `variable`
}
change variable value by +1
}

P.S. I still haven’t explained about initialization of the variable yet.

And that’s it.
It’s done!

— — — — — — — — — — — — — — — — — —

Article for next sessions: Teaching Programming to a 9-year-old: Part 2 | by Vir Gandhi| Medium

--

--