Chapter7-Iteration Statements - Counting, Totalling
Chapter7-Iteration Statements - Counting, Totalling
Solving
Lesson 4 – Iteration Statements
Learning Objective
To design pseudocodes for looping statement
Analyze the various standard methods of solution used in a
program(Counting and Totalling, maximum, minimum and
average)
Locate the syntax and logical errors in the given program
Learning Outcomes
Write pseudocode for Count- controlled ,Pre-conditioned
loop, Post- conditioned loop
Create python programs based on the given pseudocode
2
STARTER
3
Iteration
The looping can be defined as repeating the same process multiple times
until a specific condition satisfies.
There are three types of iteration statement
4
FOR... TO… NEXT REPEAT... UNTIL WHILE… DO...
7
STANDARD METHODS OF SOLUTIONS
•» Totalling
•» Counting
•» Finding maximum, minimum, and average (mean) values
•» Searching using a linear search
•» Sorting using a bubble sort.
Counting
Totalling
Keeping a count of the number of
Totalling means keeping a total that times an action is performed is
values are added to. For example, To find another standard method. For
the total mark of students in a class example, counting the total
number of students passed in a
Total ← 0 class(consider pass mark is 50)
FOR Counter ← 1 TO 30 passcount ← 0
OUTPUT ”Enter the student mark” FOR Counter ← 1 TO 30
INPUT studentmark INPUT studentmark
Total ← Total + studentmark IF studentmark > 50
NEXT Counter THEN
OUTPUT Total passcount ← passcount + 1
NEXT Counter
ACTIVITY-1
Rewrite the given program in FOR … TO … NEXT and
WHILE … ENDWHILE
Total ← 0
FOR Counter ← 1 TO 30
OUTPUT ”Enter the student mark”
INPUT studentmark
Total ← Total + studentmark
NEXT Counter
OUTPUT Total
WHILE REPEAT UNTIL
Total ← 0 Total ← 0
Counter← 1 Counter← 1
While Counter<=30 REPEAT
OUTPUT ”Enter the student mark” OUTPUT ”Enter the student mark”
INPUT studentmark INPUT studentmark
Total ← Total + studentmark Total ← Total + studentmark
Counter=Counter+1 Counter=Counter+1
End While UNTIL Counter >30
OUTPUT Total OUTPUT Total
AVERAGE Calculating the average (mean) of all the values in
a list is an extension of the totalling method.
Total ← 0
Avg← 0
FOR Counter ← 1 TO 30
OUTPUT ”Enter the student mark”
INPUT studentmark
Total ← Total + studentmark
NEXT Counter
Avg=Total/Counter
PRINT Avg
Task-1
Write pseudocode to input any 10 numbers .Find its Total and
Average
Task-2
SOLUTION:
Task-1 Task-2
count1
Total0
WHILE count<=10
Print ”Enter the number”
input Number
Total=Total + Number
count=count+1
End While
Avg=Total/count
Print “The Total is", Total
Print “The Average is", Avg
KAHOOT
https://create.kahoot.it/my-library/kahoots/227c851d-f671-4372-a62c-6050b44176d0
15
TaskWrite
TASK-1 1 an algorithm in pseudocode for any one the
given problems.
Group-1
1)To input fifty numbers and find its average
Group-2
To input fifty numbers and find the total of positive numbers
Group-3
To input fifty numbers and find the largest of the
given numbers
teachcomputerscience.co
m
GROUP-A
GROUP-C
GROUP-B
17
Past paper
practice 1)
18
SOLUTION
19
Past paper
practice 2)
20
SOLUTION
21
Past paper practice 3)
22
23
24
plenary
plenary