In this lesson, you'll build on your understanding of algorithms and flowcharts, and learn about pseudocode as a tool for planning code. You'll create your own flowcharts and pseudocode, then see how they translate into a simple program using MakeCode for micro:bit. By the end, you'll design your own algorithm from scratch.
Here's what you'll cover:
In the previous lesson we introduced you to algorithms and flowcharts, let's recap what we learned.
An algorithm is simply a step-by-step set of instructions that helps you solve a problem or complete a task. Imagine it as a clear guide that tells you exactly what to do, one thing at a time, in the right order, so you end up with the result you want.
Flowcharts are visual representations of algorithms using shapes and arrows to show the flow of steps and decisions.
Used for the start and end of the algorithm. It marks where the process begins and finishes.
Represents a process or action step, like "Display a message" or "Calculate a sum".
Indicates a decision point, where the flow branches based on a yes/no question, such as "Is it raining?".
Often used for input or output, like reading data from a user or showing results.
Shows the direction of the flow, connecting the shapes in the correct order.
Here's a simple flowchart for making a decision about going outside based on the weather: It starts with an oval 'Start', then a diamond decision 'Is it raining?', with 'Yes' leading to a rectangle 'Take umbrella' and 'No' leading to a rectangle 'Enjoy the sun', both connecting to an oval 'End'.
Now it's time to practise creating your own flowchart. You'll design a simple flowchart for an online shopping cart process using the tool you've used before at www.drawio.com.
The flowchart should represent a basic online shopping experience: starting from browsing items, deciding to add to cart, continuing shopping or checking out, and ending with payment confirmation.
Follow these steps to create your flowchart.
Note: You do not have to use this algorithm and flowchart exactly, you can design your own online shopping algorithm.
Make sure all paths connect logically with arrows showing the flow. Adjust the layout to make it clear and readable. You can add colours or resize shapes if you like. Once complete, save your diagram (you can export it as an image or PDF if you want to keep it).
Let's move on to another important tool for planning algorithms: pseudocode. Pseudocode is a way to describe the steps of an algorithm using simple, human-readable language that looks a bit like programming code, but without worrying about the exact rules of a specific programming language. It bridges your flowchart to potential code.
Pseudocode acts as a bridge between your ideas (like those in a flowchart) and actual code. It helps you outline the logic of your program clearly before you start coding. This makes it easier to spot mistakes early and ensures your algorithm is precise, finite, effective, and efficient.
IF
, ELSE
, WHILE
, FOR
, to show decisions and loops.SET
age TO
16READ
input or DISPLAY
messageIF
condition THEN
... ELSE
... END IF
WHILE
condition DO
... END WHILE
or REPEAT
... UNTIL
conditionSTART
and ends with END
Remember the weather flowchart from earlier? Here's how it might look in pseudocode:
START
IF it is raining THEN
Take umbrella
ELSE
Enjoy the sun
END IF
END
This matches the flowchart's decision diamond and process rectangles, but in text form. It's simple and helps you think through the steps before coding.
Now that you've created a flowchart for an online shopping cart process, it's time to translate that visual plan into pseudocode. This will help you practise turning your algorithm ideas into a text-based outline that's closer to actual code.
Use the flowchart you designed in the previous practical task as your guide. If you followed the suggested steps, your flowchart includes browsing items, deciding to add to cart, continuing shopping or checking out, and ending with payment confirmation. But remember, you can base this on your own version if you customised it.
Follow these steps to write your pseudocode. You can do this in a text editor, notebook, or even the notes section of your diagram tool.
START
to begin the algorithm.DISPLAY "Browse items"
.IF
statements, like IF user wants to add item to cart THEN
followed by the action, such as Add item to cart
, and ELSE
for the other path.WHILE shopping continues DO
... END WHILE
.READ payment details
or DISPLAY "Payment confirmed"
.END
.Example based on the suggested flowchart:
START
DISPLAY "Browse items"
REPEAT
IF add to cart? THEN
Add item to cart
END IF
IF checkout? THEN
READ payment details
Confirm payment
DISPLAY "Thank you for your purchase"
EXIT LOOP
END IF
UNTIL checkout is selected
END
Adapt this to match your flowchart. Make sure your pseudocode is clear, structured, and covers all the steps and decisions. Once done, review it to ensure it logically follows your flowchart and would lead to a working algorithm.