An algorithm is like a recipe in a cook book. It is a step by step set of instructions that the computer will have to follow to solve a problem or complete a task.
Algorithms consist of step by step instructions which are listed in order and will be executed in the same order, one instruction at a time: this is called sequencing.
On occasions a set of instructions needs to be repeated several times which is done in programming using a loop: this is called iteration.
Computers also have to take decisions as to whether or not to run a set of instructions or to bypass these instructions. In programming these decisions are coded using IF statements: this is called selection.
Complex algorithms can use a range of sequencing, iteration and selection blocks.
To design an algorithm you can draw a flowchart or write pseudo-code.
Your algorithm (flowchart or pseudo-code) can then be converted by a programmer using the programming language of their choice (e.g. Python, Java, Visual Basic, etc.)
Coding Challenges
We have designed five algorithms (See flowcharts below). Your task is to implement each of these algorithms using Python code.
- 1 hour = 3600 seconds
- 1 minute = 60 seconds
Python Code
Complete the code using the trinket below:
This algorithm is a good example of:
The following algorithm is used to test if a year is a leap year or not.
Python Code
This algorithm is a good example of:
The following algorithm can be used to display the dates of the next ten Winter Olympics.
Python Code
This algorithm is a good example of:
Python Code
This algorithm is a good example of:
Python Code
This algorithm is a good example of:
Extension Tasks
Use the same approach to complete the following “Flowchart to Python” challenges:
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area