AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Plans before programs

Week 1 · 1.1 Pseudocode · 3 lessons
1

Halfway to a program

Computing 8: Topic 1.1, pp. 9–26
GoalExplain what pseudocode is, why designers use it and what it must still contain.
New words
pseudocode · a way of writing an algorithm that looks like code but is not a real language, so a computer cannot run itsyntax · the rules for how words and symbols must be writtenlanguage-independent · can be turned into any programming languagestatement · one instruction on one line
Explanation

An algorithm can be shown in plain English, as a flowchart, as pseudocode or as a Python program. Pseudocode sits halfway between a flowchart and a real program. It looks like code, with command words and variables, but it is not a real language, so no computer can run it. It has no fixed syntax, so one instruction can be written in several correct ways. It is language-independent: a Python programmer and a programmer who uses another language can both read the same plan. Designers use it to think about the steps, variables and calculations without worrying about colons and brackets. It must still use the same constructs as real programs: sequence, selection and iteration. In these lessons we use one house style, but other books and teachers may write pseudocode differently.

Worked examples
In EnglishFlowchart boxPseudocodePython
Ask how many loaves are wantedINPUT loavesINPUT loavesloaves = int(input("Loaves? "))
Show the words Thank youOUTPUT "Thank you"OUTPUT "Thank you"print("Thank you")
The same two instructions are shown four ways. Read across each row. Pseudocode is closer to Python than English is, but it has no colons, brackets or int().
LineValid pseudocode?Reason
INPUT loavesyescommand word and a variable
READ loavesyesanother command word, but the meaning is clear
INPUTnono variable, so the value would not be stored
get something from someonenono command word and no variable
Not every line is valid pseudocode. A valid line needs a clear command word, and a variable if data must be stored. Different command words are allowed when the meaning is clear.
Pseudocode
1INPUT loaves
2total ← loaves * 3
3OUTPUT "Pay ", total
Output
Pay 12
This pseudocode is a plan for a bakery till. A bread roll costs 3. With 4 rolls the program shows Pay 12. A Python programmer could now write total = loaves * 3, and a programmer using another language could do the same.
Class activity

Plan in pairs (no computer). Each person invents a tiny program for a bike shop, a choir or a market stall, and writes it as three or four lines of pseudocode with at least one INPUT and one OUTPUT. Swap papers. Your partner writes one plain English sentence for each line, then checks with you whether the meaning is the same. Next, change one command word (for example INPUT to READ) and decide together whether the pseudocode is still valid. If you have a computer or tablet, type the program in Python afterwards.

Practice
1
Which of these lines are valid pseudocode? Give a reason for any that are not.
LineStatement
AINPUT cost
Bask the user, then maybe keep it somewhere
COUTPUT "Hello"
DREAD cost
2
Rewrite this Python program as pseudocode in the house style.
Python
1team = input("Team? ")
2players = int(input("Players? "))
3print("Team " + team)
4print(players * 2)
3
A designer in one country writes an algorithm in pseudocode. A programmer in another country uses a different programming language. Give two reasons why pseudocode helps them.
4
Say whether each statement is true or false, and correct the false ones. (a) A computer can run pseudocode directly. (b) Pseudocode has no fixed syntax. (c) Pseudocode can ignore sequence, selection and iteration.