top of page

Coding and Problem-Solving



There's a lot of overlap between the skills needed for coding and problem-solving. Indeed, the most relevant skill for learning to code is to break down a problem into small, logical steps that follow in a clear order. The "words" and "grammar" of the coding language are important, but they're not the most important aspect of coding.


When kids or adults learn to code, the main challenge is learning to think computationally. For example, in after school coding courses for kids, apart from introducing the Python language to the students, we're helping them learn how to think logically and solve problems.


First, solve the problem. Then, write the code

- John Johnson


Let's look at a few examples to show how coding and problem-solving are closely linked.


Drawing a Flower


I'll start with a computer program in which the task doesn't seem like a "problem". However, the process of writing code is still a problem-solving one.

One of the projects we use early on in our courses for kids is to get them to draw a flower like this one:


Efficiency is a key part of writing computer code. We're always looking for the best ways to solve a problem which makes our coding simpler and the code run smoother. Students have already learned how to move the "drawing pen" on the screen forward, turn left and right, and draw dots of any colour. We ask them to come up with the steps needed to draw this flower in the simplest possible way.


You can try this out before you read on. Get a sheet of paper and a pen or pencil, or open a file where you can type in some text on your computer, and try to write the steps needed to draw this flower if you can move forward, turn, and draw a dot. The pen starts in the middle of the screen and is facing towards the right.

Here's my suggestion:

  1. Move the pen forward by a certain distance, so it's away from the centre

  2. Draw a pink dot

  3. Move the pen backwards by the same amount as in Step 1 so that it's back to the centre

  4. Turn the way you're holding the pen so that the pen is "pointing" in a different direction, ready to move in a different direction

  5. Repeat Steps 1 to 4 for the number of petals needed

  6. Finally, draw a large green dot in the centre

Here is a visual representation of this process showing how these steps combine to draw the flower:



The "problem" we're trying to solve here is how to move the pen in the simplest and easiest fashion. Coding and problem-solving are indeed one and the same thing.


Filtering a List of Names


Here's a list of names:

  1. Amelie

  2. Jason

  3. Mary

  4. Penny

  5. Trevor

  6. Paul

  7. ...

The list goes on and contains 1,000 names in total. A task we use to consolidate and introduce a number of key topics in coding is the following. We ask students to write code that will extract all the names in this list that start with a certain letter, for example, "P".


As in the previous example, we ask students to solve the problem before writing the code. This means writing the steps that they would need to take if they were to perform this task by hand. The instructions we give them are not to take anything for granted and to list every single step they may need, no matter how obvious it may be.


You can try this exercise yourself before you read on.


Here is one set of steps you could use:

  1. Look at the first name in the list

  2. Look at the first letter of that name

  3. If that letter is "P", write the name on a separate sheet of paper

  4. If that letter is not "P", do nothing

  5. Move on to the next name in the list, and repeat steps 1-4 for the second name, and for every name in the list, one at a time

These two examples may seem like simple problems to solve. But they help students learn how to break down a problem into very small steps and to order them in a logical way.


Coding and Problem-Solving


Learning to solve problems is an important skill when learning to code. However, this is also true in reverse. As kids learn how to code and become more proficient, their problem-solving skills improve as they practise more coding. However, these problem-solving skills go beyond coding. Indeed, the ability to solve problems is a skill our children will need in their future lives, whether they choose to pursue coding or not.


Here at codetoday we offer Python programming classes for children. Our classes are delivered live online, and we even offer a completely FREE intro lesson - no card or payment details needed and no commitment to subscribe. Book a FREE kids' coding lesson now.




70 views

Comments


Python Coding for Young People

CT-Unlimited-FinalRAW-transparent.png

Codetoday Unlimited is for the curious teenager or preteen keen to learn proper Python coding. Stephen's courses start from the basics and carry on to intermediate and advanced levels.

Python Coding for Adults

The Python Coding Place is Stephen's platform full of courses and other resources for beginners and intermediate learners. The focus is on clarity and Stephen's unique communication style.

bottom of page