Professional Documents
Culture Documents
Finding Errors (Past Paper Questions With Answer) - Unlocked
Finding Errors (Past Paper Questions With Answer) - Unlocked
Paper-II
“Identify errors in given algorithms and suggest ways of
removing these errors”
Compiled by:
Nouman
Shamim
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Nouman Shamim
Syllabus Reference
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
2 Read this section of program code that should input 10 positive numbers and then output the
smallest number input.
1 Small = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
6 Counter = Counter + 1
7 PRINT Small
Locate these errors and suggest a corrected piece of code for each error.
1 .......................................................................................................................................................
2 .......................................................................................................................................................
3 .......................................................................................................................................................
4 .......................................................................................................................................................
1 1 mark for each error identified + suggested
correction Line 1 or Small = 0: this should read
Small = 999
line 5 or IF…: this should read IF Num < Small THEN Small = Num
line 8 or UNTIL: this should read UNTIL Counter = 10 or
UNTIL Counter > = 10 or
UNTIL Counter > 9
line 7 or PRINT…: PRINT Small should come after the end of the repeat
loop or
line 8 or UNTIL: this should come before line 7
[4]
Principal Examiner Report
Question 2
Most candidates located at least one error and suggested a suitable piece of corrected code.
The error on line 8 was often identified, with better candidates providing a working correction.
farhan.rahmat@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
2 Read this section of program code that should input 30 positive numbers and then output the
largest number input.
1 Large = 9999
2 Counter = 0
4 DO
5 INPUT Num
7 Counter = Counter - 1
8 ENDWHILE
9 PRINT Large
Locate these errors and suggest a corrected piece of code for each error.
1 .......................................................................................................................................................
..........................................................................................................................................................
2 .......................................................................................................................................................
..........................................................................................................................................................
3 .......................................................................................................................................................
..........................................................................................................................................................
4 .......................................................................................................................................................
......................................................................................................................................................[4]
2 Read this section of program code that should input 50 numbers and then output the average.
1 Total = 0
2 For Counter = 1 TO 50
3 INPUT Num
4 Total = Total + 1
5 Counter = Counter + 1
6 Average = Total/Counter
7 NEXT Counter
8 PRINT Average
Locate these errors and suggest code corrections to remove each error.
1 .......................................................................................................................................................
..........................................................................................................................................................
2 .......................................................................................................................................................
..........................................................................................................................................................
3 .......................................................................................................................................................
..........................................................................................................................................................
4 .......................................................................................................................................................
......................................................................................................................................................[4]
Many candidates located at least one error and suggested a suitable piece of corrected
code. The errors on lines 4 and 5 were frequently identified, with stronger responses
providing a working correction. The question asked the candidates to identify and correct
each error; a few candidates either identified the error or corrected the error, but both actions
were required to gain each mark. farhan.rahmat@gmail.com
Topical Questions of O Level Computer Science 2210 by Nouman Shamim
1 Total = 0
2 PosCount = 0
3 FOR Counter = 1 TO 50
4 INPUT Num
7 Average = Total/PosCount
8 NEXT Counter
9 PRINT Num
Locate these errors and suggest code corrections to remove each error.
1 .......................................................................................................................................................
2 .......................................................................................................................................................
3 .......................................................................................................................................................
4 .......................................................................................................................................................
......................................................................................................................................................[4]
line 7 Average = Total/Poscount: this should come after the end of the repeat loop
2 Read this section of program code that inputs 10 positive numbers and then outputs the smallest
number input.
1 Small = 1000
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Small = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Small
(i) Identify three changes you would need to make to find the largest number input instead
of the smallest number.
1 .........................................................................................................................................
...........................................................................................................................................
2 .........................................................................................................................................
...........................................................................................................................................
3 .........................................................................................................................................
.......................................................................................................................................[3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[3]
farhan.rahmat@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
1 Large = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num > Large THEN Large = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Large [3]
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
2 Read this section of program code that inputs 10 positive numbers and then outputs the total.
1 Total = 0
2 Counter = 0
3 REPEAT
4 INPUT Num
5 Total = Total + Num
6 PRINT Total
7 Counter = Counter + 1
8 UNTIL Counter = 10
1.................................................................................................................................................
...................................................................................................................................................
2.................................................................................................................................................
...................................................................................................................................................
3.................................................................................................................................................
...............................................................................................................................................[3]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
(i) Most candidates correctly suggested that the PRINT Total statement should be after the
end of the loop. Many candidates correctly identified that the input needed to be checked to
see if it was positive or suggested that the loop should be a FOR … NEXT loop.
(ii) Most candidates correctly moved the PRINT Total statement. Some candidates correctly
converted the REPEAT … UNTIL loop to a FOR … NEXT loop. Some candidates attempted
the validation check; a common error was to total too few positive numbers.
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
2 Read this section of program code that inputs positive numbers, discards any negative numbers
and then outputs the average. An input of zero ends the process.
1 Total = 0
2 Counter = 100
3 REPEAT
4 REPEAT
5 INPUT Num
6 UNTIL Num < 0
7 Total = Total + 1
8 Counter = Counter + Num
9 UNTIL Num = 0
10 Average = Total / (Counter - 1)
11 Print Average
Error 1 ..............................................................................................................................................
Correction .........................................................................................................................................
Error 2 ..............................................................................................................................................
Correction .........................................................................................................................................
Error 3 ..............................................................................................................................................
Correction .........................................................................................................................................
Error 4 ..............................................................................................................................................
Correction .........................................................................................................................................
..................................................................................................................................................... [8]
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
2 1 mark for identifying each error, 1 mark for the corresponding change
Most candidates correctly identified at least one error. Few candidates showed
understanding of the program code by suggesting that the UNTIL Num < 0 should be
replaced by UNTIL Num >= 0 to allow the process to end correctly. Many candidates
correctly identified that Counter and Total were updated incorrectly and could provide the
necessary corrections.
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
Oct/Nov 2016 P23
• inputs 10 numbers
• checks whether each number is within a specified range
• totals the numbers within the range and outside the range
1 InRange = 0
2 OutRange = 1000
3 FOR Count = 1 TO 10
4 INPUT Num
5 IF Num > 10 AND Num < 20 THEN InRange = InRange + 1
6 ELSE OutRange = OutRange - 1
7 Count = Count + 1
8 NEXT X
9 PRINT InRange, OutRange
Error 1........................................................................................................................................
Correction ..................................................................................................................................
...................................................................................................................................................
Error 2........................................................................................................................................
Correction ..................................................................................................................................
...................................................................................................................................................
Error 3........................................................................................................................................
Correction ..................................................................................................................................
...................................................................................................................................................
Error 4........................................................................................................................................
Correction ..................................................................................................................................
...............................................................................................................................................[4]
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
(b) Decide, with reasons, whether the numbers 10 and 20 are within or outside the range.
Within
range (✓) Outside
Number range (✓) Reason
10
……………………………………………………………………..
……………………………………………………………………..
20
……………………………………………………………………..
……………………………………………………………………..
[4]
2 (a) 1 mark for each change
– Line 2: OutRange = 0
– Line 6: should be OutRange = OutRange + 1
– Line 7: not needed
– Line 8: NEXT X should be NEXT Count / Line 3: FOR Count = 1 TO 10 should be
FOR X = 1 TO 10 [4]
(b)
[4]
Principal Examiner Report
Question 2
(a) The full range of marks was seen for this question on errors within program code, with
candidates’ correct responses divided amongst all the correct possibilities. Common errors
included giving an incorrect initial value to OutRange, such as 1, or applying an incorrect
variable to NEXT X, such as NEXT Number.
(b) Most candidates correctly identified that both 10 and 20 were outside the range. Better
candidates gave good reasons for this being the case. Common mistakes were for
candidates to not fully explain their reason, such as by simply stating erroneous or invalid
data, which was not enough for the reason mark.
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
May/June 2017 P21
2 This section of program code asks for 50 numbers to be entered. The total and average of the
numbers are calculated.
1 Total = 0
2 Counter = 50
3 PRINT ′When prompted, enter 50 numbers, one at a time′
4 REPEAT
5 PRINT ′Enter a number′
6 INPUT Number
7 Total + Number = Total
8 Number = Number + 1
9 UNTIL Counter = 50
10 Average = Number * Counter
11 PRINT ′The average of the numbers you entered is ′, Average
State the line number for each error and write the correct code for that line.
Correct code.............................................................................................................................
Correct code.............................................................................................................................
Correct code.............................................................................................................................
Correct code.............................................................................................................................
[4]
1 mark for each error identified and suggested correction (the corrected code must be written in
full)
Line 2 Correct code Counter = 0 (1)
farhan.rahmat@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
May/June 2017 P22
4 An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used.
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum
Error........................................................................................ ...................................................
(b) Rewrite the correct algorithm using a more suitable loop structure.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
farhan.rahmat@gmail.com
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
nouman.shamim@gmail.co
m
Topical Questions of O Level Computer Science 2210 by Farhan Rahmat
Oct/Nov 2017 P22
Oct/Nov 2017 P23
2 This section of program code asks for 80 numbers between 100 and 1000 to be entered. It checks
that the numbers are in the correct range, and stores them in an array. It counts how many of the
numbers are larger than 500 and then outputs the result when the program is finished.
1 Count = 0
2 FOR Index = 1 TO 80
3 INPUT 'Enter a number between 100 and 1000', Number
4 WHILE Number = 99 AND Number = 1001
5 INPUT 'This is incorrect, please try again', Number
6 ENDWHILE
7 Num[80] = Number
8 IF Number > 500 THEN Count = Count + 1
9 UNTIL Index = 80
10 PRINT Index
11 PRINT ' numbers were larger than 500'
State the line number for each error and write the correct code for that line.
Nouman.shamim@gmail.com
Question Answer Marks
2 1 mark for each error identified plus suggested correction (the corrected 4
lines must be written in full)
Nouman.shamim@gmail.com
Topical Questions of O Level Computer Science 2210 by Nouman Shamim
May/June 2018 P21
1 Total = 100.00
2 PRINT ′Enter the height of each member of your class, one at a
time, when prompted′
3 FOR Count = 1 TO 30
4 PRINT ′Enter a height in metres′
5 INPUT Height
6 Total = Total + Height
7 PRINT Total / 30
8 Count = Count + 1
9 NEXT Count
State the line numbers that contain the errors and describe how to correct each error.
Error 1 .......................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Error 2 .......................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Error 3 .......................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[1]
Nouman.shamimt@gmail.com
Topical Questions of O Level Computer Science 2210 by Nouman Shamim
Nouman.shamimt@gmail.com
Topical Questions of O Level Computer Science 2210
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
1 count = 0
2 product = 0
3 while count <= 10 do
4 input number
5 product = product * number
6 count = count + 1
7 print product
8 endwhile
(a) There are three errors in the algorithm. Locate and describe these errors. [3]
(b) A while … do loop has been used in the algorithm. State another type of loop that
could have been used. [1]
12 A golf course charges $10 for each game of two people. Each additional person incurs
afurther charge of $2 per game. If they book two or more games in advance, they get a
10%discount on the total charge.
The following program has been written in pseudocode to calculate the charges for a
game.
1 extracost = 0
2 input numberpeople, numbergames
3 charge = 10 * numbergames
4 extrapeople = numberpeople – 2
5 if numberpeople< 2 then extracost = 2 * extrapeople * numbergames
6 charge = extracost
7 if numbergames> 1 then charge = charge * 0.1
8 print charge
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
There are three errors in the program. Locate these errors and suggest a correct piece
ofcoding. [6]
12 1 mark for each error identified + 1 mark for each suggested correction
– error
line 5: numberpeople < 2 is incorrect
correction:
numberpeople > 2
– error
line 6: the formula/charge = extracost is incorrect
correction:
charge = extracost + charge
– error
line 7: discount calculation/charge = charge * 0.1 is incorrect,
correction:
charge = charge * 0.9 [6]
1 negative = 1
2 positive = 1
3 for count = 1 to 20 do
4 input number
5 if number < 0 then negative = negative + 1
6 if number > 0 then positive = positive + 1
7 count = count + 1
8 print negative, positive
9 next count
9 1 mark for each error and 1 mark for reason why it is an error
– line 1/negative=1 and/or line 2/positive=1
– negative and/or positive should be set to zero
– line 7/count=count+1
– don’t need a count within a for …. to next loop
– replace loop with a repeat...until loop
– line 8/print negative, positive or line 9/next count
– outputs should come after the next count statement [6]
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
May/June 2011 P12
7 (a) Read the following section of code that inputstwenty (20) numbers and then outputs
the largestnumber input.
1h=0
2c=0
3 REPEAT
4 READ x
5 IF x > h THEN x = h
6c=c+1
7 PRINT h
8 UNTIL c < 20
There are THREE errors in this code.
Locate these errors and suggest a corrected pieceof code. [3]
7 (a) 1 mark for each error identified + suggested correction
line 5: this should read if x > h then h = x
line 7: print h should come after the end of the repeat loop
line 8: this should read until c = 20 or until c >= 20 or until c > 19 [3]
8 A piece of pseudocode was written to input 1000 positive numbers and then output
thehighest and lowest numbers.
10 highest = 0
20 lowest = 0
30 for count = 1 to 100
40 input number
50 if number > highest then number = highest
60 if number < lowest then number = lowest
70 count = count + 1
80 next count
90 print highest, lowest
(8) 1 mark for error + 1 mark for suggested correction to error (max of FOUR errors)
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
May/June 2014 P12
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
error 1 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 2 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 3 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 4 .......................................................................................................................................
correction ..................................................................................................................................
...................................................................................................................................................
error 5 .......................................................................................................................................
correction ..................................................................................................................................
............................................................................................................................................... [5]
6 (a) 1 mark for each error and suggested correction (accept description or example of
corrected pseudocode).
error: line 10: total = 1
correction: totals should be set to zero; total = 0
error: line 30: … number < 10 …
correction: check should be made if number > 10; … number > 10 …
error: no input inside loop
correction: input number
error: line 50: x = x + 1
correction: for … to loops don’t need a counter; remove line 50 altogether
error: line 80: output x
correction: output should be total value; output total [5]
(b) The corrected algorithm was converted to a computer program and run. However,
after several numbers were input, the program stopped and an error message was
generated, showing that there was a further error at line 40 (k = x / number).
State what could cause this error to occur.
...................................................................................................................................................
...................................................................................................................................................
Suggest a change to line 40 to overcome this problem.
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................... [2]
(b) division by zero error (or similar description of error produced when dividing by 0)
add an error trap after input of number
e.g. 40 if number = 0 then k = 0 else k = x/number [2]
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
Oct/Nov 2014. P13
Nouman4@gmail.com
Topical Questions of O Level Computer Science 2210 by nouman
shamimt
Practice Questions:
Questions 1 to 3 contain sections of pseudocode which contain errors. Locate the errors
and suggest the correct coding. Questions 4 to 10 are problems which require an algorithm
to be written in pseudocode – there is “no right answer” here; as long as the pseudocode
works then the solution is acceptable.
(1) The following section of pseudocode inputs 1000 numbers and then outputs how many
were negative, how many were positive and how many were zero.
Locate the 3 errors and suggest a corrected piece of code.
1 negative 1: positive 1
2 for x 0 to 1000
3 input number
4 if number < 0 then negative negative + 1
5 if number > 0 then positive positive + 1
6 endif
7 endif
8 next
9 print negative, positive
(2) The following section of pseudocode inputs rainfall (in cm) for 500 days and outputs the
average rainfall and the highest rainfall input.
Locate the 3 errors and suggest a corrected piece of code.
1 highest 1000
2 days 1
3 while days > 0
4 input rainfall
5 if rainfall > highest then highest rainfall
6 endif
7 total total + rainfall
8 days days + 1
9 average total/500
10 endwhile
11 print average, highest
1 input n
2 for mult 1 to n
3 sum 0
4 sum sum * mult
5 result n/sum
6 next
7 print result
Nouman4@gmail.com