0% found this document useful (0 votes)
1 views10 pages

Python L4 Writing algorithms

This document introduces the concept of writing algorithms and pseudocode, emphasizing its role in planning before coding. It outlines the types of programming errors, including syntax, run-time, and logic errors, and provides examples of pseudocode for various scenarios. Additionally, it encourages debugging practices through exercises to identify and correct errors in sample programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views10 pages

Python L4 Writing algorithms

This document introduces the concept of writing algorithms and pseudocode, emphasizing its role in planning before coding. It outlines the types of programming errors, including syntax, run-time, and logic errors, and provides examples of pseudocode for various scenarios. Additionally, it encourages debugging practices through exercises to identify and correct errors in sample programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Writing algorithms

Introduction to Python
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
Introduction to Python
Writing algorithms

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

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

You might also like