How to get your child fired up about computer programming

“You have two choices,” I tell a group of seventh and eighth graders at the Summers-Knoll school.
“Option A. You get $50.” Hmm, sounds good, says the look on their faces.
“Option B. You get the sum of one cent, plus two cents, plus three cents, and so on, up to a dollar. Which one do you want?”
The students pause to think about the problem. Pencil and paper, that’s one way to figure out which option gives more money.
We discuss how generations of cranky math teachers have used this sum of integers as busy work so they don’t have to teach. One student says she had such a teacher.
Math prodigies like Gauss solved the problem in a heartbeat, as one can derive a formula for this sum. However, it’s not my intention to teach them this trick.
I give them the option to solve the problem with pencil and paper, or I can show them how solve it with a computer program. They choose the latter.
As they fire up their Chromebooks, a hushed silence descends over the room. I have their full and undivided attention.
Problem based, math programming course
During the 2016–2017 school year, I experimented with how to teach programming at the Summers-Knoll School in Ann Arbor, Michigan. My methods differ from the typical programming courses in two ways.
First, I provide motivation for why they should use a computer. These problems range from summing a sequence of numbers to designing a book.
The typical programming course jumps right into the boring details without offering a reason for the drudgery. This problem extends to all other subjects, as my teachers never provided motivation to learn anything from subtraction to thermodynamics.
Instead, I look for problems and activities that motivate basic programming concepts like iteration and conditionals. My observations of math classes at Summers-Knoll, especially those of Susan Carpenter, inspired this approach.
Second, the students use programming to solve math problems and explore numbers. Other courses look to engage your child through video games and web design, both worthy pursuits.
However, my experience has shown that students get excited about doing math on the computer. This is fortunate, as programming is a basic part of 21st century numerical literacy.
This article explores what I’ve learned from teaching computer programming at Summers-Knoll. The two lessons described here worked well both in the middle school and in a third and fourth grade classroom.
However, not all the lessons worked, and I describe the failures as well.
Iteration and Money
The students had the option of $50 or the sum of one cent, two cents, and so on up to a dollar. This requires summing the numbers one through a hundred on the computer.
To solve this problem, we use an online python executor. I chose Python because it’s a language that actual programmers like myself use. While drag and drop languages like Scratch exist, none of my students have had an issue typing out code.
I use an online python executor to make life simple. Often, people who want to learn programming get stuck with the details of setting up the software. The online application skips this large hurdle.
Once the children get set up online, I show them how to sum consecutive numbers in Python. First, I ask them to type the following code.

Line 2 shows them how to define a list of consecutive integers. In line 3, they create the same list with a function called range.
The print statement in line 5 lets you look at the two lists. The students execute the code to show that these two lists are the same.
It might seem strange that the range function takes 1 and 5 as the arguments that denote the start and end of the sequence. Computer programmers have a long history of labeling the first element as zero. This implies the sequence stops one number before the end argument of 5.
Then I show them the following code.

- In line 2, we set a variable sum to 0.
- range(1, 101) is a list of numbers from 1 through 100.
- In line 3, the syntax “for i in list” iterates, or goes through, every element in the list.
- In line 4, we add an integer to our running sum.
- In line 6, we print out the sum after summing from one through a hundred.
The children press execute, and the code gives an answer of 5050. Take the sum of one through a hundred cents over $50.
Note that the program takes four lines of code, which makes it simple. When developing problems for young students, I make sure I can write the code in less than a minute. If it takes longer, the program is most likely too complicated for a beginner.
Summing the odd integers
After the students master summing the integers, I ask them to sum over the odd integers. This requires a modification of the range function discussed above. Try it: range(1, 11, 2).
The children eventually see a pattern emerge:
1 + 3 = 4
1 + 3 + 5 = 9
1 + 3 + 5 + 7 = 16
1 + 3 + 5 + 7 + 9 = 25
The sum of odd integers is the squares of the integers. For example, 4 is 2 times 2, 9 is 3 times 3, etc. I ask them to prove this statement, which really means drawing a picture that gives insight into the statement.
Try it for yourself. If you get stuck, the delightful answer is on page 114 of Paul Lockhardt’s The Mathematician’s Lament.
Failure with the law of large numbers
With the same seventh and eighth graders, I did another lesson with flipping coins. With the same iteration methods as the previous section, I wanted to show them the law of large numbers.
With more flips of the coin, the fraction of heads gets closer to the expected one half. The law of large numbers requires this, and we were going to use computer code to show it.
We set up the code to iterate over different numbers of coin flips. The children saw how the fraction of heads got closer to one half with more flips.
However, the experiment never lit their fire to play with code. The lesson lacked a problem to solve. It was more like a typical lecture to show some arcane law.
Art, Design and the Golden Ratio
Before the NCAA tournament, I talked to the middle school students on my work in data science: predicting the outcome of March Madness. I use data to calculate the probability for each team to win the tournament.
I spiced up the presentation this year with a “hands on” demonstration. I took the final four teams in the Big Ten tournament and grabbed all the scores from regular season games between these teams. I asked the students to predict the outcome of the tournament.
Most of the students enjoyed the activity… except for two. I lost their attention before I could finish the words “college basketball.”
This disappointment led to motivation. I knew these students both liked art, since they doodled during math time.
How do you motivate math to the artistic student? The Golden Ratio and Fibonacci series, of course.
This led to a book design activity.
I brought in cardstock and asked the children to cut out the most aesthetic rectangle for the shape of their book. Then we measured the ratio of the long to short edges.
Next, we designed the cover. The children picked a title, which had to be long enough to fit over two lines.
I used image software to adjust the vertical spacing between the two lines until everyone agreed. Then we looked at the ratio between the tops of the two lines and the height of the character.

In both the book shape and title spacing, we found ratios near 1.61, the Golden Ratio. This number seems to appear in aesthetically pleasing items.
Next, we jumped on the Chromebooks to show how this ratio emerges from simple rules. Let’s start a sequence of numbers with 1 and 1. To generate the next number, we add the last two numbers in the sequence.
1, 1, 2, 3, 5, 8, 13, 21, 35, …
This is the famous Fibonacci series first suggested by Leonardo of Pisa in the 13th century. To generate this series, we wrote this code.

- In line 2, we start our list with the first two elements
- In line 4, we iterate an arbitrary number of times. The kids like to goof off and put in a million just to break the site. Not recommended.
- In line 5, we generate the next number in the sequence by taking the sum of the last two. The index -1 and -2 get the last and second to last items in a list, respectively.
- In line 6, the function append puts a number at the end of the list.
- In line 7, we look at the ratio of the last two integers in the list. Note this requires the function float() to turn the integer in the decimal. If you forget this step, you don’t get the decimal answer for the Golden Ratio. Try it.
The code shows how the ratio of consecutive numbers in the Fibonacci sequence goes to the Golden Ratio.
Next, I ask the students to change the two starting numbers of the sequence in line 2. Try this yourself and see how the Golden Ratio is “universal.”
The lesson ends with watching Donald Duck in Mathmagic Land. This video has some beautiful animations of how the Golden Ratio appears in man-made and natural objects.
It might seem odd that I used a Disney video made in 1959 to show the Golden Ratio. However, my attempts to find a better, more recent video came up empty. They either induce pure boredom or have narrator on a double hit of speed.
Our world has created plenty of high quality science content like Cosmos and Particle Fever. The same quality math content does not exist, for the Golden Ratio or otherwise. This is a sad state for a world in need of more data scientists.
Outlook
In my experiences at Summers-Knoll, I’ve found students get excited about code when presented a problem or activity. It’s a 21st century approach to teaching math.
In these two examples, I showed the students how to write the computer code, explaining each line along the way. This presents basic ideas like iteration.
However, the students are not yet using computer code to solve their own problems. At what point does this happen?
I don’t know. I’ll be working weekly with a class of third and fourth graders next year to see when they spread their wings and take flight.
