Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

Python L4 Writing algorithms

The document outlines the learning objectives and success criteria for writing algorithms in pseudocode, emphasizing the importance of planning before coding. It provides examples of pseudocode and tasks for constructing algorithms based on specific conditions, along with a discussion on types of programming errors and debugging exercises. The document serves as a guide for beginners to understand algorithm writing and its application in programming with Python.

Uploaded by

sahmad2344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Python L4 Writing algorithms

The document outlines the learning objectives and success criteria for writing algorithms in pseudocode, emphasizing the importance of planning before coding. It provides examples of pseudocode and tasks for constructing algorithms based on specific conditions, along with a discussion on types of programming errors and debugging exercises. The document serves as a guide for beginners to understand algorithm writing and its application in programming with Python.

Uploaded by

sahmad2344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

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.

You might also like