# Coding and Problem-Solving

We don't teach coding to kids so that they can become software developers in the future. The main reason we teach them coding is that **it teaches them how to solve problems**. Coding and problem solving go hand-in-hand. Indeed, computer coding is an exercise in problem-solving using the tools provided by a programming language.

Coding is still a subject that's often misunderstood. We have recently created a Parents' Guide to Coding to help parents navigate this subject.

One of the best quotes about coding comes from Apple's co-founder and long-term CEO, Steve Jobs, who said that "Everybody should learn to program a computer, because it teaches you how to think".

## How To Write A Computer Program

Consider how you could write a computer program that shows a ball falling from a height and bouncing on the ground. Here are some steps you may write:

Create an object that represents the ball.

Make the ball move down by a small step.

Next, make the ball move down by a step slightly larger than the previous one since gravity accelerates the ball downwards.

Keep moving the ball down, one step at a time, with the step size increasing each time.

Each time the ball moves down, you need to look at the ball's position, though, to make sure it hasn't reached the ground yet.

When the ball does reach the ground, you need to reverse the direction of the ball's movement.

As the ball is now rising, each time the ball moves you need to make the step with which it moves smaller, as gravity is now slowing the ball as it moves upwards.

Once the step size becomes zero, the ball will no longer keep moving upwards. The step size will still be reduced the next time and this will now make the step size negative. So the ball will start falling again.

This example shows how programming requires you to think carefully about the situation you're trying to represent with your computer program and break it down into small steps. You cannot skip any of the steps as the computer program will not workâit will not show the ball falling and bouncing realistically.

Let's look at another example. You want to work out the odds of getting four heads in a row when you flip a coin. You can do this purely using knowledge of mathematics and probability, but you decide you want to do this by writing a computer program. You have a problem you're trying to solve, and if you can find a good and efficient solution then you can get the computer to do the hard work for you.

Here are the steps you could use:

Get the computer to choose a random item from "Heads" and "Tails".

If it's "Heads", get the computer to choose again, for the second time.

If it's "Heads", get the computer to choose again, for the third time.

If it's "Heads", get the computer to choose again, for the fourth time.

If it's "Heads", keep a note that you've managed to get four heads in a row.

If you get "Tails" in any of the above steps, do nothing! Just move on.

Now, repeat Steps 1-6, let's say, a million times. You'll end up with a tally showing how many times you got four consecutive "Heads" out of the million attempts. If you want a more accurate estimate, repeat for 10 million times or more if you want.

You still need to know how to translate these steps from English into Python or whatever programming language you'd like to use, but that's only one part of coding. **The thinking and problem-solving aspects of computer programming are, in many ways, the most important part**. It's also the most exciting part of coding.

Solving a problem and writing a computer program that works and does what you want it to do is very rewarding and satisfying.

## Problem Solving In The Curriculum

Learning to solve problems has always been a part of the curriculum of what children learn. Some topics in Maths are particularly suited to train children not just to learn those Maths topics but also to learn how to solve problems.

In recent times, there has been a lot of discussion about introducing more critical thinking in our children's education. However, good schools and good teachers have always included this as it's always been a key part of a good education.

**Coding is a subject that provides plenty of opportunities for problem-solving**. It's a great subject to add to the others, such as Maths, as a way of both teaching children a new skill but also, more generally, help them think about problems and find creative solutions for them.