Math is often at the bottom of the list when it comes to popular school subjects. Some students find it boring. Others find it confusing. Some even find it terrifying. Teachers often hate it too – many people say it’s the hardest subject to teach.
In this post, we want to explain a few ways that math can be supported by coding. We’ll start by talking about some general points, like the way that coding can be used to make numbers a lot less scary, and help children to visualize abstract concepts easily. After that, we’ll give some specific examples of coding activities that teach geometry, arithmetic, and graphing.
General principles
To begin with, let’s look at how coding can help with general mathematical learning, like a lack of confidence when it comes to numbers, and difficulties visualizing sums. If you’d like to jump straight to some specific activities, feel free to scroll down the page.
Patience and problem-solving
Math is all about problem-solving. That’s pretty much the definition: finding solutions to number-based problems. As luck would have it, coding is all about problem-solving too.
It’s something every coder is familiar with. They’ve spent ages working on a piece of code, but when they tell it to run, nothing happens. With a sigh, they now have to track down the problem, and work out how to fix it. This process is called debugging, and it’s great problem-solving practice for kids.
If a child does enough debugging, they’ll learn how important and useful it is to stay calm, patient, and methodical. Getting angry, or frustrated, won’t help them. It will only make things harder.
The same principle applies to mathematics. When a child is confronted by a tricky sum, it won’t help to tear up the piece of paper, or throw a ruler across the classroom. Instead, they need to take a deep breath, and approach the problem calmly and methodically, just as they would do when debugging a line of code.
In other words, by teaching them patience, coding helps kids to get better at math. This helps in other subjects too, and in general day-to-day life. Patience is such an important skill, and coding is a great way to learn.
Bringing numbers to life
Coding is also a useful way to turn numbers and sums into something tangible and visual. For example, a kid could code a purple cat to walk across the screen. Maybe they’ll start with 10 steps, before changing that number to 20. The kid can see that the purple cat walked twice as far, because 10 x 2 = 20.
It all sounds pretty straightforward, but for some children, seeing numbers in action can be really, really useful. Abstract numbers are scary, whereas visual examples, like the one we described, are much more familiar and secure.
In the past, to help a student visualize a number, teachers would usually get out some little bricks or beads. A child can count 10 of them, then add another 10, and see how the pile grows to 20. This is still a good option, but it falls short when you get to higher numbers. Nobody has time to count 100 beads, then double that number to 200.
But with coding, kids can make the purple cat walk 200 steps with just a few more clicks. And as they get more competent, they can make things a lot more complicated.
For example, they could tell the cat to jump after every 20 steps. Now, the child can count the jumps, and see how the cat jumped a total of 10 times over the course of 200 steps. In other words, 200 ÷ 20 must equal 10. It’s another example of an abstract sum being brought to life.
Kids could use this jumping cat for other sums as well. Tell the cat to walk 248 steps, and jump every 7 steps. Before running the code, the kid could grab a piece of paper, and do some long division: 7 into 248. The answer should help to predict how often the cat will jump. 35 jumps, with 3 steps remaining? Run the code, and find out.
Making math less scary
A lot of kids are scared of math. Even the sight of numbers can leave them feeling stressed. They’re frightened of being wrong, or they’re frightened of looking stupid, and math lessons fill them with dread. But coding can help to ease these fears by allowing children to negotiate numbers in a safe, easy space.
That example we gave earlier, about the purple cat, was explicitly about practicing mathematical sums, but it really doesn’t need to be. Instead, a kid could sit down at their computer, and start coding something unrelated. They could try to make a video game, where the player is controlling a dancing bear, and trying to make it jump through as many golden hoops as possible.
While programming the bear, the kid will find themselves handling numbers, without even noticing what’s happening. How high can the bear jump, and at what angle? That’s some basic geometry right there. What’s the highest possible score, and can anyone beat it? They’re arranging numbers into order.
Suddenly, they realize that numbers aren’t scary after all. If they can handle them inside a coding environment, why can’t they handle a mathematical context too? Their stresses and fears will melt away, as they discover that numbers aren’t as bad as they always seemed.
When it comes to coding, no matter the project, numbers are bound to crop up. Whether they’re plotting movement, or tracking high scores, numbers are always needed – and with time, a child’s numerical confidence will grow.
Specific activities
So far, we’ve kept things general: coding can make children more patient and methodical, it can help them to visualize abstract sums, and it can make numbers feel less scary. Now, we’re going to get more precise, with some specific examples of mathematical principles which can be taught with the help of code.
Geometry
Let’s talk about that purple cat again. It’s a great way to teach geometry to kids: getting the cat to move around the screen.
For example, you could ask them to code the cat to move five steps forward, then turn 90°, and take another two steps after that. It’s basic geometry. Some addition too. How many steps will the cat take in total? Best of all, it’s visual learning. When they run the code, they’ll see the cat slide across the screen.
Now, you want to ask the child to change a few of the numbers. Boost the angle to 180°. Add another three steps, and see what happens. Hopefully, the purple cat ends up back where it originally started.
Now, you can make things harder. Challenge them to make the purple cat walk in a perfect square. Take five steps, turn 90°; take five steps, turn 90°; take five steps, turn 90°, take five more steps…
How about a triangle? How about a hexagon? The possibilities are endless. We know that a kid could be drawing these shapes on paper instead, with a trusty pencil and protractor, but there’s something more satisfying about moving a purple cat around. The visualization is a lot more memorable, and most importantly, a lot more fun.
If you’re looking for a readymade example of this, this is a good place to start. The cat in this example is orange, not purple, but it’s still an excellent activity.
Arithmetic
Learning times tables can be dull and frustrating, but code can be used to enhance the experience, and make arithmetic more exciting. Instead of listing the answers out loud, children can create an interactive game that tests them on their knowledge instead. The program might ask “What is 5 x 10?” and the player has to type the answer.
The Raspberry Pi Foundation has a great template for this, which you can access here. Instead of a purple cat, the questions are asked by a red monkey. The players get 30 seconds to answer as many of these questions as possible – a timer is a great way to make this more challenging, and to get kids feeling competitive.
Can they beat their last high score? Can they beat their friend’s high score? Suddenly, they don’t feel like they’re doing math. They’re playing a game, and finetuning their skills, and getting better and better as they go.
This doesn’t just work for multiplication. They could program the game to ask them about addition, subtraction or division. Older students could get it to give them algebra questions or trigonometry too. Overall, it’s a great way to learn, and just like using code to draw geometric shapes, the possibilities are pretty much endless.
Graphing
This is another good way to use coding to teach math, and it’s also covered by a Raspberry Pi template. If you’re interested in that, you can find it here. An important aspect of math is the process of collecting and analyzing data. For example, finding out how many people in the class like pizza, and working out which toppings are most popular.
Once a child has collected this important data, there are many ways to represent it. They could draw a pie chart on a piece of paper, or use spreadsheet software like Microsoft Excel or Google Sheets.
Alternatively, they could program these graphs into being. This is higher-level coding than some of the activities we’ve already talked about, and it will require students to use a text-based language like Python. But if they’re ready to give it a go, it’s an excellent way to practice mathematics through code.
One thing is certain: it feels a lot more satisfying to build a pie chart using your own piece of code, instead of leaving Excel to do all the hard work for you. This is yet another brilliant example of the ways that coding and mathematics often go hand in hand.
Final words
After reading this post, hopefully you have a good idea of the ways that coding can be used to teach mathematics. The main takeaway is this: it can turn the subject into something fun, and visual, using game mechanics and purple cats to transform a student’s experience.
There are hundreds of activities for students to try, and with a bit of googling, you’ll find plenty of excellent options. Some students already love mathematics, and might not benefit from any of this. But for others, these activities could be life-changing. Instead of growing up with a fear of math, they’ll become calm and confident in the company of numbers, and maybe even find it fun.
We also invite you to try out the Dodo Does Math course, which combines math and coding in a fun and engaging way.