- Terminator
- Process
- Decision
- Input/output
Pseudocode and flowcharts
Revision notes
Algorithms can be written as pseudocode, as flowcharts, in OCR Exam Reference Language or in a high-level language. You need to create, read, complete, correct and refine algorithms in these forms. Expect flowchart symbols, completing code with gaps and writing short algorithms.
Key facts
- Rounded rectangle = terminal (Start / Stop)
- Parallelogram = input or output
- Rectangle = process (calculation or assignment)
- Diamond = decision (two exits: Yes / No)
- Rectangle with double side lines = sub program
- Arrow back to an earlier step = a loop
- Pseudocode: English-like steps, one per line, indented
- ERL = OCR Exam Reference Language, used for code in the exam
Notes
Flowchart symbols
diagram
- Terminal (rounded rectangle): Start or Stop.
- Input/output (parallelogram): data coming in or results going out, such as 'Input age' or 'Output total'.
- Process (rectangle): a calculation or assignment, such as 'total = total + price'.
- Decision (diamond): a question with two exits, labelled Yes and No (or True and False).
- Sub program (rectangle with a double line down each side): runs a separately defined sub program.
- Lines with arrows show the direction of flow. A loop is an arrow that goes back to an earlier step.
The flowchart symbols A flowchart with a loop: the No arrow goes back to an earlier step
Pseudocode and Exam Reference Language
- Pseudocode is a way of writing an algorithm in structured, English-like steps. It does not follow the exact rules of any one language.
- Write one step per line and indent the lines inside loops and if statements, so the structure is clear.
- Nesting is putting one selection or loop inside another, such as an if statement inside a for loop. Indent each level further so it is clear which block each line belongs to.
- Questions in the exam show code in OCR Exam Reference Language (ERL). You need to be able to read it and write it.
- Example in ERL: a program that averages five numbers.
total = 0 for i = 1 to 5 num = int(input("Enter a number")) total = total + num next i print("Average: " + str(total / 5))
Which form can you answer in?
- When a question just says 'Write an algorithm', you can usually answer in pseudocode, a flowchart, ERL or a high-level language.
- When a question says you must use OCR Exam Reference Language or a high-level programming language (as in Section B), flowcharts, pseudocode and English gain no marks.
- Small syntax slips are not usually penalised if the logic is clear, but missing logic always loses marks.
How to answer each type of question
Identify flowchart symbols
- Match the shape to its job: rounded = terminal, parallelogram = input/output, rectangle = process, diamond = decision.
- Give the name only; no description is needed unless asked.
Example. State the purpose of each flowchart symbol.
(a) Diamond (b) Parallelogram (c) Rounded rectangle (d) Rectangle [4]
Show the model answerHide the model answer
Complete an algorithm with gaps
- Read the description of what the algorithm should do.
- Work out what each gap must be for that to happen: a condition, a variable, a value or an operator.
- Check your answer by tracing it with one or two test values.
Example. The algorithm should keep asking for a password until Tiger7 is entered, then output Welcome. Complete the gaps (1) to (3).
password = input("Enter password")
while password ....(1).... "Tiger7"
print("Incorrect")
password = ....(2)....
endwhile
print(....(3)....)[3]Show the model answerHide the model answer
!=input("Enter password")"Welcome"Write an algorithm (Section A)
- List the requirements in the question: each one is usually worth a mark.
- Set any totals or counters to 0 before a loop.
- Put the inputs that repeat inside the loop, and the final output after it.
- Indent the code inside loops and if statements.
Example. Write an algorithm that asks the user to enter the ages of 20 people, then outputs how many of them are 18 or over. [5]
Show the model answerHide the model answer
count = 0
for i = 1 to 20
age = int(input("Enter age"))
if age >= 18 then
count = count + 1
endif
next i
print(count)Loop that repeats 20 times (1); age input inside the loop (1); checks age >= 18 (1); adds 1 to a counter that was set to 0 before the loop (1); outputs the counter after the loop (1).Don’t lose marks
- Decision boxes with unlabelled exits, or with only one exit.
- Using a process rectangle for an input or output.
- Forgetting to set a total or counter to 0 before the loop.
- Putting the output inside the loop, so it is shown every time instead of once at the end.
- Answering in a flowchart or in English when the question demands ERL or a high-level language.
More tips
Memory tricks
- Flowchart shapes: Round = Run or stop, Parallel = Put in or out, Rectangle = do something, Diamond = Decide.
- Every decision diamond has one way in and two labelled ways out.
- Before writing code, jot down the inputs, the loop, the decision and the output: that is the skeleton of most answers.
Exam technique
- Look for the sentence 'You must use either OCR Exam Reference Language or a high-level programming language'. If it is there, write code.
- Use meaningful variable names and indentation: it makes your logic easy for the examiner to follow and credit.
- Trace your finished algorithm with a simple test value to check it does what the question asks.
What each grade needs
What you need to be able to do, from the first marks up to the top grade.
- Grade 3Name the flowchart symbolsTerminal, input/output, process, decision and sub program symbols, joined by arrows.
- Grade 4Follow a flowchart or pseudocode to find outputsWork through each step with given inputs, following the correct branch at each decision.
- Grade 5Complete missing parts of an algorithmFill gaps in pseudocode or a flowchart so that it meets the description.
- Grade 6Write an algorithm with selection and iterationWrite pseudocode or draw a flowchart that uses decisions and loops correctly.
- Grade 7Convert between a flowchart and codeTurn a flowchart into code, or code into a flowchart, keeping the same logic.
- Grade 8Refine an algorithm to meet new requirementsChange an existing algorithm, such as adding validation or a counter, without breaking it.
Quick recall
- State what the flow lines (arrows) in a flowchart show.
- The order (direction) in which the steps are followed.
- Give two reasons why a programmer might plan an algorithm in pseudocode before writing the program in a programming language.
- Quicker to write; no strict syntax; can be turned into any language; logic planned first.
- How many flow lines normally leave a decision symbol in a flowchart?
- Two
Sample questions
- asks the user to enter the number of adult tickets and the number of child tickets
- calculates the total price, applying the discount when it is due
- outputs the total price.
Show the answer and mark scheme
adults = int(input("Number of adult tickets"))
children = int(input("Number of child tickets"))
total = adults * 32 + children * 18
if adults + children >= 5 then
total = total * 0.9
endif
print(total)- inputs the number of adult tickets and the number of child tickets
- calculates adults × 32 + children × 18
- checks whether adults + children is 5 or more
- applies the 10% discount correctly (e.g. total × 0.9)
- outputs the total price (after the discount check)
- £118.80
01 correct = "Pa55word"
02 attempt = input("Enter password")
03 while attempt != correct
04 print("Incorrect")
05 attempt = input("Enter password")
06 endwhile
07 print("Access granted")Account locked instead of Access granted.You must use either OCR Exam Reference Language or a high-level programming language that you have studied.
Show the answer and mark scheme
- the user has an unlimited number of attempts
- so someone could keep guessing / use a brute-force attack until they find the password
correct = "Pa55word"
attempt = input("Enter password")
tries = 1
while attempt != correct AND tries < 3
print("Incorrect")
attempt = input("Enter password")
tries = tries + 1
endwhile
if attempt == correct then
print("Access granted")
else
print("Account locked")
endif- uses a counter that is initialised (to 0 or 1) before the loop
- increments the counter each time a password is entered
- loop stops when the password is correct OR three attempts have been made
- outputs "Access granted" only when the password is correct
- outputs "Account locked" after three incorrect attempts
More in Designing, creating and refining algorithms
Stuck? Get 1-to-1 help.
Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.