Writing Algorithms
Learning Objective Success Criteria
• Learn to write algorithms in • Purpose of algorithms
pseudocode • Learn the Pseudocode language
• Converting Pseudocode into a
program
Introduction to Python
Writing algorithms
Starter - What does this
algorithm do?
#GhostHunter
if ghost catches man then
lives lives – 1
if lives = 0 then
display "Game Over!"
else
display "Arghhh!"
Introduction to Python
Writing algorithms
Writing Pseudocode
• Pseudocode is half code, half English
• It has no real syntax and would not run
• It is a structured sequence of instructions
• It is useful for planning algorithms
Use it to plan before coding!
Introduction to Python
Writing algorithms
Suggested language for
Pseudocode
• Use indentation in pseudocode
• Use words such as:
print, display, input, output, calculate, add,
set, reset, if, then, else
Introduction to Python
Writing algorithms
Pseudocode Example:
if unlock button pressed then
display PIN unlock screen
input PIN
if correct PIN entered then
unlock phone
else display “Try again”
else display lock screen
Introduction to Python
Writing algorithms
Writing an Algorithm
• Write a pseudocode algorithm to display the correct
hat size based on the circumference of your head:
Less than 57cm = Small
Greater than 60cm = Large
Anything in between = Medium
Introduction to Python
Writing algorithms
Now write the code…
• You should understand the problem more clearly
• It should be easier to write – in any language!
Introduction to Python
Writing algorithms
Task
• You must construct pseudocode that will select
seasons “Spring, Summer, Autumn, Winter” dependent
on each covering 3 months?
• You must now code the above pseudocode to see if it
works;
Tips
• You must show an ‘else’ if the input is incorrect;
• You can use the ‘elif’ function.
Introduction to Python
Writing algorithms
Answer:
Introduction to Python
Writing algorithms
Types of programming error
• Syntax Errors
• Run-Time Errors
• Logic Errors
Introduction to Python
Writing algorithms
Debugging exercise
• Look at the two programs below and see if you can
find and correct the errors in them
SeasonFinderBUGS.py
TaxCalculatorBUGS.py
Introduction to Python
Writing algorithms
Plenary
• What are the three different Syntax errors?
• Explain each one.