དཔལ་ལྡན་འབྲུག་གཞུང་།
ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
PYTHON FOR BEGINNERS
Classes IX and X ICT Curriculum
ALGORITHM & FLOWCHART
July 2023
Developed by Thinley & ICT teachers of Thimphu for ICT teachers of Bhutan as reference material
Algorithm
A step-by-step solution for specific problem
Why learn Algorithm?
❖ To understand the core idea behind a problem.
❖ To understand the flow of the problem.
❖ To give the designer a clear explanation of the needs and goal of the issue.
❖ To find a solution for the problem.
❖ To provide a straightforward explanation of how it works without getting into too
much technical detail.
❖ To analyze and evaluate the complexity (in terms of time and space) of a problem.
Algorithm
❖ An algorithm is a set of well-defined steps or instructions used to solve specific
problems or perform a particular task.
❖ Writing algorithms involves breaking down a complex problem into smaller and
more manageable steps. Usually, one of the following conventions is used while
writing algorithms:
○ Written descriptions.
○ Pseudo code.
❖ For an algorithm, you need to specify:
1) Input
2) Process
3) Output
Characteristics of Algorithm
❖ Clear: The steps in the algorithm should be easy to understand.
❖ Unambiguous: The steps in the algorithm should have only one possible
interpretation.
❖ Inputs: The algorithm should have one or more inputs.
❖ Outputs: The algorithm should have one or more outputs.
❖ Finite: The algorithm should terminate after a finite number of steps.
❖ Effective: The algorithm should produce the correct output for the given input.
❖ General: The algorithm should be able to work with different inputs and produce
the correct output.
❖ Independent: The algorithm should be independent of any programming
language.
Characteristics continue...
Example 1
Problem: Write an algorithm to multiply any two numbers and print the result.
STEP Algorithm
1 START
2 Take input for x and y variable from the user.
3 Multiply x and y variables using * operator and assign the result to z
4 Print the variable Z
5 STOP/End
Example 2
❖ Design an algorithm to add any two numbers and display the result.
STEP Algorithm
1 START
2 Read any two numbers x , y
3 addition = x + y
4 Print addition
5 STOP/End
Example 3
Problem: Write an algorithm to find the greatest of two numbers.
STEP Algorithm
1 START
2 Read any two numbers a, b
3 Check if a>b:
4 Print “a is greater than b”
5 Else:
6 Print “b is greater than a”
7 STOP/End
Activities
Activity 1: Write an algorithm that adds two numbers.
Activity 2: Write an algorithm to find the area of the circle.
Activity 3: Write an algorithm to calculate the perimeter of a rectangle.
Activity 4: Write an algorithm for finding the largest of any three given numbers.
Activity 5: Write an algorithm that prompts the user to input their exam marks and
determines whether they have passed or failed. The pass mark is 40 out of 100.
Answers
Activity 1: Write an algorithm that adds two numbers.
STEP Algorithm
1 START
2 Read any two numbers a, b
3 addition = a + b
4 Print addition
5 STOP/End
Answers 2
Activity 2: Write an algorithm to find the area of the circle.
STEP Algorithm
1 START
2 Read a radius of circle (r)
3 area = PI*r**2
4 Print area
5 STOP/End
Answers 3
Activity 3: Write an algorithm to calculate the perimeter of a rectangle.
STEP Algorithm
1 START
2 Read a length and width [l, w]
3 perimeter = 2*(L+W) OR perimeter = l+w+l+w
4 Print perimeter
5 STOP/End
Answers 4
Activity 4: Write an algorithm for finding the largest of any three given numbers.
STEP Algorithm
1 START
2 Read any three numbers x, y and z
3 Check if x>y and x>z:
4 Print “x is greater than y and z”
5 Check if y>x and y>z:
6 Print “y is greater than x and z”
7 else:
8 Print “z is greater than x and y”
9 STOP/End
Answers 5
Activity 5: Write an algorithm that prompts the user to input their exam marks and
determines whether they have passed or failed. The pass mark is 40 out of 100.
STEP Algorithm
1 START
2 Enter any mark [m]
3 Check if m>=40:
4 Print ”Passed”
5 else:
6 Print “Failed”
7 STOP/End
Flowchart
Diagrammatic representation of an algorithm
Flowchart
❖ A flowchart is a diagrammatic representation of an algorithm. It is a way of
visualizing the steps involved in a process or task.
❖ A flowcharts can be helpful for both writing programs and explaining programs to
others.
❖ Some of the most common symbols used to draw flowcharts are:
◆ Start/End: The START and End of a flowchart can be represented by the oval
shape.
◆ Process: The process of a flowchart can be represented by the rectangle shape.
◆ Decision: The Decision of a flowchart can be represented by the diamond shape
◆ Input/Output: The input/output of a flowchart can be represented by the
parallelogram shape
Symbols
Example 1
Draw a flowchart to find the addition of any two numbers.
STEP Algorithm START
1 START
Read any two numbers x, y
2 Read any two numbers x, y
3 addition = x + y
addition = x + y
4 Print addition
5 STOP/End Print addition
End
Example 2
Draw a flowchart to calculate the perimeter of a Square with side length of 5 units.
Algorithm 1. Flowchart
Step 1: START
Step 2: Store the value of a side in a variable named side
Step 3: Calculate and store the value of perimeter in the
variable named perimeter
Step 4: Display the perimeter
Step 5: END
Example 3
Draw a flowchart to check whether the entered age is eligible for casting the vote.
STEP Algorithm
1 START
2 Enter an age:
3 Check if age>=18:
4 Print “Eligible to cast vote”
5 else:
6 Print “Not eligible to cast vote”
7 STOP/End
Activities
Activity 1: Draw a flowchart to find multiplication any numbers entered by the user.
Activity 2: Draw a flowchart to find the area of the circle.
Activity 3: Draw a flowchart to calculate the perimeter of the rectangle.
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
Activity 5: Draw a flowchart that prompts the user to input their ICT exam mark and
determines whether they have passed or failed. The pass mark is 40 out of 100.
Answer 1
Activity 1: Draw a flowchart to find multiplication any numbers entered by the user.
START
Read any two numbers x, y
multiplication = x * y
Print multiplication
End
Answer 2
Activity 2: Draw a flowchart to find the area of the circle.
START
Read radius of circle [r]
area = PI*r**2
Print area
End
Answer 3
Activity 3: Draw a flowchart to calculate the perimeter of the rectangle.
START
Read a length and width [l, w]
perimeter = 2*(l+w)
Print perimeter
End
Answer 4
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
START
Read any three numbers x,y,z
Check
Yes
x>y and x>z Print “x is greater than y and z”
No
Yes End
Check Print “y is greater than x and z”
y>x and y>z
No
Print “z is greater than x and
y”
Answer 4
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
End
Print “x is greater than y and z”
Check
yes
x>y and x>z Read any three numbers x,y,z
No
Start
Check yes
Print “z is greater than x and y”
y>x and y>z
No
Print “y is greater than x and z”
Answer 5
Activity 5: Draw the flowchart that prompts the user to input their ICT exam mark and
determines whether they have passed or failed. The pass mark is 40 out of 100.
START
Enter a mark [m]
yes No
Check
m>=40
Print “Passed” Print “Failed”
End