Writing Algorithms Introduction to Python Introduction to Python

  • Slides: 10
Download presentation
Writing Algorithms Introduction to Python

Writing Algorithms Introduction to Python

Introduction to Python L 4 Writing Algorithms Learning Objectives • Learn to write algorithms

Introduction to Python L 4 Writing Algorithms 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 L 4 Writing Algorithms What does this algorithm do? #Ghost. Hunter

Introduction to Python L 4 Writing Algorithms What does this algorithm do? #Ghost. Hunter if ghost catches man then lives – 1 if lives = 0 then display "Game Over!" else display "Arghhh!"

Introduction to Python L 4 Writing Algorithms Writing Pseudocode • • Pseudocode is half

Introduction to Python L 4 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 L 4 Writing Algorithms Suggested language for Pseudocode • Use indentation

Introduction to Python L 4 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 L 4 Writing Algorithms Pseudocode Example: if unlock button pressed then

Introduction to Python L 4 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 L 4 Writing Algorithms Writing an Algorithm • Write a pseudocode

Introduction to Python L 4 Writing Algorithms Writing an Algorithm • Write a pseudocode algorithm to display the correct hat size based on the circumference of your head: Less than 57 cm = Small Greater than 60 cm = Large Anything in between = Medium

Introduction to Python L 4 Writing Algorithms Now write the code… • You should

Introduction to Python L 4 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 L 4 Writing Algorithms Types of programming error • Syntax Errors

Introduction to Python L 4 Writing Algorithms Types of programming error • Syntax Errors • Run-Time Errors • Logic Errors

Introduction to Python L 4 Writing Algorithms Debugging exercise • Look at the two

Introduction to Python L 4 Writing Algorithms Debugging exercise • Look at the two programs below and see if you can find and correct the errors in them Season. Finder. BUGS. py Tax. Calculator. BUGS. py