Question 17

AQA Computer Science Specimen Paper 1B (8525/1B)GCSE3 marks

On the specification

17.1
3.2 Programming
17.2
3.2 Programming
17.3
3.2 Programming
Question text

17 Figure 8 shows a Python program that is being developed. It is supposed to calculate and display the highest common factor of two numbers entered by the user. The highest common factor of two numbers is the largest number that both numbers can be divided by without leaving a remainder. Examples: • the highest common factor of the numbers 6 and 9 is 3 • the highest common factor of the numbers 2 and 5 is 1 Line numbers are shown but are not part of the program code. Figure 8 1 num1 = int(input()) 2 num2 = int(input()) 3 hcf = 1 4 count = 1 5 while count < num1: 6 if (num1 % count == 0 and num2 % count == 0): 7 hcf = count 8 count = count + 1 9 print(hcf) The program in Figure 8 works correctly sometimes but not always. When the user enters the numbers 4 and 6 it correctly outputs 2, but when the user enters the numbers 4 and 4 it should output 4 but it does not. 17.1 State the output from the program in Figure 8 when the user enters the numbers 4 and 4. [1 mark] 17.2 State the line number from the program in Figure 8 which contains the error that stops the program from sometimes working correctly. [1 mark] 17.3 Describe how the line of code identified in your answer to Question 17.2 should be changed so that the program in Figure 8 will work correctly. [1 mark]