logo

Pearson Edexcel GCSE (9-1) Computer Science practice

A student wrote the following pseudocode to calculate the sum of numbers from 1 to 5: ``` 1. SET total TO 0 2. SET count TO 1 3. WHILE count < 5 4. total = total + count 5. count = count + 1 6. END WHILE 7. PRINT total ``` The expected output is 15. When the student runs the code, the output is 10. a) State the type of error present in the pseudocode. b) Explain why this error occurs in the given pseudocode. c) Describe how the student could correct this error. [5 marks]

Try the question first, then check the answer and practise the same topic again.

At a glance

Question

Type

exam_style

Style

Topic

Algorithms

Exam-style question

Try this first

A student wrote the following pseudocode to calculate the sum of numbers from 1 to 5: ``` 1. SET total TO 0 2. SET count TO 1 3. WHILE count < 5 4. total = total + count 5. count = count + 1 6. END WHILE 7. PRINT total ``` The expected output is 15. When the student runs the code, the output is 10. a) State the type of error present in the pseudocode. b) Explain why this error occurs in the given pseudocode. c) Describe how the student could correct this error. [5 marks].

Answer and explanation

Concise answer

a) The type of error present is a logic error.

Why this is correct

1 mark for stating 'logic error'. 1 mark for identifying the incorrect loop condition ('count < 5'). 1 mark for explaining that count = 5 is not included in the sum due to the condition. 1 mark for suggesting to change the comparison operator ('<='). 1 mark for explaining that this change will include the final value and achieve the correct sum.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

Flashcard 1 of 6

Press Space to flip, arrows to move

Related practice questions