Uploaded by unn4eva

Algorithms, Flowcharts, Pseudocode: Intro & Python Implementation

advertisement
Algorithm, Flowchart, Pseudocode
What’s an algorithm?
Step-by-step instructions for solving a problem.
What’s a flowchart?
A pictorial representation of an algorithm.
What’s a pseudocode?
A textual representation of an algorithm.
Algorithms can be represented as
pseudocodes or flowcharts
Think-Pair-Share
Identify the images below.
Pseudocode or Flowchart?
START
INPUT number1, number2
sum = number1+number2
OUTPUT sum
What does the algorithm do?
STOP
What are the key features of
Pseudocode
the algorithm?
What programming techniques
are used in the algorithm?
Flowchart
Let’s try to implement the algorithm using Python.
Do you think the algorithm below will work as it is?
Let’s find out.
You will need the Python IDLE to run this program
Try the program. See if there is a need to make to
adjustments to make the program produce the right result
Corrected Code
Important terms to note in the programs above.
1. VariablesA memory location where data are stored. (eg num1, num2,
total)
2. Data typesThe kind of data or value a variable holds. (eg integer, float,
string, character)
3. Concatenation – The joining of two or more strings
What would you do to the program above to change it to:
Subtraction of two numbers
Division of two numbers
Multiplication of two numbers
Implement the program using Python
Exercises – Attempt this individually
1. Change this algorithm so that it outputs
the name and age that the user has input in
a sentence
name = input("Enter your name")
3. Change this algorithm so that if the
user enters the "+" symbol,
the two numbers are added together
age = input("Enter your age")
number1 = input("Enter a number")
print("Hello ", name)
number2 = input("Enter a number")
2. Change this algorithm so that it only
outputs "Valid" when the number is greater
than 0
symbol = input("Enter the symbol")
value = input("Enter a number")
print(number1 * number2)
if(value > 10):
print("Valid")
if(symbol == "*"):
Flowchart symbols and Uses
Convert all the
algorithms written to
flowcharts
Introduction to Flowgorithm
Download