Skip to content
IGCSE·Tuition
Computer Science · Practice

Problem-solving explanations: original mixed practice with explanations

Written explanations improve fastest when you write your own answer first and only then compare.

These questions cover the whole problem-solving explanations module: the purpose of a variable, justified test cases, described corrections, traces linked to output and minimal examples. They are original and ordered from easier to harder.

Write your answer in full sentences first. For traces, draw the table.

Then open the answer and compare. The restricted pseudocode trace trainer and the safe Python reasoning sandbox can check your values.

Questions

1. (Easy) Explain the purpose of Count in this code.

Count ← 0
FOR Index ← 1 TO 4
   INPUT Age
   IF Age >= 18 THEN
      Count ← Count + 1
   ENDIF
NEXT Index
OUTPUT Count
Show answer

Count is a counter. It holds how many of the ages entered so far are 18 or over. It starts at 0 because none have been counted yet, increases by 1 only when Age >= 18 is true, and is output after the loop as the final number.

2. (Easy) A search sets Found ← FALSE before a loop and Found ← TRUE when the target is seen. Explain why Found is needed.

Show answer

Found is a flag that records whether the target has been seen. It starts FALSE because nothing is found yet. Once set to TRUE it stays TRUE, so after the loop the program can test it to decide whether to output “Found” or “Not found”.

3. (Easy) Requirement: a seat number must be a whole number from 1 to 40 inclusive. Give four boundary tests with expected results and reasons.

Show answer
  • 1: accepted, because “from 1” includes the lower limit.
  • 40: accepted, because “to 40 inclusive” includes the upper limit.
  • 0: rejected, because it is just below the lower limit.
  • 41: rejected, because it is just above the upper limit.

4. (Medium) Requirement: delivery is free when the order total is RM150 or more. Give three tests, with expected result and reason.

Show answer
  • RM149.99: delivery charged, because it is just below the limit.
  • RM150: free delivery, because “or more” includes exactly RM150. This catches a wrong > instead of >=.
  • RM200: free delivery, as a normal value well inside the rule.

5. (Medium) Describe the correction. The prices 5, 6 and 7 should give 18 but the code outputs 7.

1  Total ← 0
2  FOR I ← 1 TO 3
3     INPUT Price
4     Total ← Price
5  NEXT I
6  OUTPUT Total
Show answer

Line 4 replaces Total with the latest Price instead of adding to it, so only the last price, 7, is left. Change it to Total ← Total + Price. The values then become 5, 11, 18, which is the expected output.

6. (Medium) This code should output 1, 2, 3 and then stop, but it never ends. Describe the correction.

1  Count ← 1
2  WHILE Count <= 3 DO
3     OUTPUT Count
4  ENDWHILE
Show answer

Count is never changed inside the loop, so Count <= 3 stays true forever and 1 is output again and again. Add Count ← Count + 1 as the last statement inside the loop, after the OUTPUT. Then Count goes 1, 2, 3, 4 and the loop ends after outputting 1, 2, 3.

7. (Medium) Trace the code, state the output and explain it in one sentence.

X ← 3
Y ← 0
WHILE X > 0 DO
   Y ← Y + X * X
   X ← X - 1
ENDWHILE
OUTPUT Y
Show answer
PassX > 0 ?Y afterX after
Start03
13 > 0 true92
22 > 0 true131
31 > 0 true140
Test0 > 0 false140

Y adds the squares 9, 4 and 1. The loop stops when X becomes 0, and OUTPUT Y prints 14.

8. (Medium) Trace the code and give both outputs.

Even ← 0
Odd ← 0
FOR N ← 1 TO 6
   IF N MOD 2 = 0 THEN
      Even ← Even + N
   ELSE
      Odd ← Odd + N
   ENDIF
NEXT N
OUTPUT Even
OUTPUT Odd
Show answer

N = 1: Odd 1. N = 2: Even 2. N = 3: Odd 4. N = 4: Even 6. N = 5: Odd 9. N = 6: Even 12. Even collects 2 + 4 + 6 and Odd collects 1 + 3 + 5. The outputs are 12 and then 9.

9. (Hard) A student says the output of question 7 is 0 “because X ends at 0”. Explain the error.

Show answer

The student has read the wrong variable. 0 is the final value of X, which ended the loop, but the statement is OUTPUT Y. The last value in the Y column is 14, so the output is 14. The student should name the variable in the OUTPUT statement first, then read its column.

10. (Hard) A long program should count values above 10. For the data 5, 10, 15 it outputs 2. Write a minimal reproducible example with expected and actual output, and describe the correction.

Show answer
Data[1] ← 5
Data[2] ← 10
Data[3] ← 15
Count ← 0
FOR I ← 1 TO 3
   IF Data[I] >= 10 THEN
      Count ← Count + 1
   ENDIF
NEXT I
OUTPUT Count

Expected: 1 (only 15 is above 10). Actual: 2 (10 and 15). The condition uses >=, which includes 10, but the requirement says “above 10”. Change it to IF Data[I] > 10 THEN. Data on the boundary, 10, is what exposes the fault.

11. (Hard) A test plan for “a score from 0 to 100 inclusive” uses 0, 50, 100 and 101. State what is missing and why it matters.

Show answer

There is no test just below the lower limit, −1. Without it, a rule that wrongly accepts negative scores would pass the plan. A wrong-type value such as “ten” would also be useful, because the rule says the score is a number. Add −1 (rejected, below the lower limit) and “ten” (rejected, not a number).

If you got these wrong

Use the mistake log and retest queue to note the type of error and retest it a few days later. The module overview, problem-solving explanations, shows the full route.

If you would like someone to read your written answers alongside the mark points, our teachers can do that in online one-to-one Computer Science tuition.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If your answers are close to the worked ones but keep missing one required point, a one-to-one teacher can read your sentences beside the mark points and show where the gap is.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service