Download presentation
Presentation is loading. Please wait.
1
Writing algorithms Introduction to Python
2
Learning objectives Learn to write algorithms in pseudocode
Review the difference between syntax errors, run- time errors and logic errors Learn techniques for debugging programs
3
What does this algorithm do?
#GhostHunter if ghost catches man then lives lives – 1 if lives = 0 then display "Game Over!" else display "Arghhh!"
4
Use it to plan before coding!
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!
5
Suggested language for Pseudocode
Use indentation in pseudocode Use words such as: print, display, input, output, calculate, add, set, reset, if, then, else
6
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
7
Anything in between = Medium
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
8
Now write the code… You should understand the problem more clearly
It should be easier to write – in any language!
9
Types of programming error
Syntax Errors Run-Time Errors Logic Errors
10
Debugging exercise TaxCalculatorBUGS.py
Look at the two programs below and see if you can find and correct the errors in them SeasonFinderBUGS.py TaxCalculatorBUGS.py
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.