Photo AI

Figure 8 shows a Python program that is being developed - AQA - GCSE Computer Science - Question 17 - 2021 - Paper 1

Question icon

Question 17

Figure-8-shows-a-Python-program-that-is-being-developed-AQA-GCSE Computer Science-Question 17-2021-Paper 1.png

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 ... show full transcript

Worked Solution & Example Answer:Figure 8 shows a Python program that is being developed - AQA - GCSE Computer Science - Question 17 - 2021 - Paper 1

Step 1

State the output from the program in Figure 8 when the user enters the numbers 4 and 4.

96%

114 rated

Tired rob

Only available for registered users.

Sign up now to view full answer, or log in if you already have an account!

Answer

When the user enters the numbers 4 and 4, the program will output 1. This is because the while loop checks for the condition count < num1, and since count is initialized to 1, it only correctly calculates the highest common factor for values below the minimum of 4.

Step 2

State the line number from the program in Figure 8 which contains the error that stops the program from sometimes working correctly.

99%

104 rated

Tired rob

Only available for registered users.

Sign up now to view full answer, or log in if you already have an account!

Answer

The error is in line 6.

Step 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.

96%

101 rated

Tired rob

Only available for registered users.

Sign up now to view full answer, or log in if you already have an account!

Answer

To fix the program, line 6 should be modified to ensure that the count variable is checked against both numbers correctly. The modified line should be:

while count <= num1:

This change allows the loop to run up to the value of the numbers entered, ensuring that the highest common factor can be correctly determined.

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

Other GCSE Computer Science topics to explore

;