Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: Unit 2.3 Maintainability
Time allowed: 40 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
Turn over
Section A: Core Skills
1
A software development company has a team of 20 programmers working on a single large project.

(a) Explain why the use of comments is essential when multiple programmers are working on the same file.
[2]

(b) Apart from comments, state one other technique that makes code easier to read for other programmers.
[1]
Section B: Applied Maintenance
2
The following algorithm calculates the pay for a worker. However, the programmer has used poor variable names, making it difficult to maintain.
x = float(input("Enter number: ")) y = float(input("Enter number: ")) z = x * y print("Total is: " + str(z))
Rewrite the algorithm above.
You must change the variable names to be meaningful and follow standard conventions. The logic must remain exactly the same.
[3]
3
In Python, indentation defines the structure (blocks) of the code.
Look at the two code snippets below. They contain the exact same text, but the indentation of Line 04 is different.

Snippet A:
01 score = 10 02 if score > 5: 03 print("Start") 04 print("End")
Snippet B:
01 score = 10 02 if score > 5: 03 print("Start") 04 print("End")
(a) State the output of Snippet A.
[1]

(b) State the output of Snippet B if score is changed to 2.
[1]

(c) Explain how the indentation of Line 04 changes the logic of the program between Snippet A and Snippet B.
[2]
Turn over
4
A student has written a program that repeats the same code three times to draw three squares.
# Square 1 print("Moving Forward") print("Turning Right") print("Moving Forward") print("Turning Right") # ... (lines repeated for remaining sides and squares)
(a) This approach is inefficient and hard to update. Refine this solution by defining a subprogram (function) named draw_square().
[3]

(b) Explain how using this subprogram makes the code more maintainable if the student decides to change the shape from a Square to a Triangle later.
[2]
5
A program calculates the area of circles. The value 3.14 is used in 50 different places throughout the 1000-line code.
area1 = 3.14 * (radius1 * radius1) # ... 500 lines later ... area2 = 3.14 * (radius2 * radius2)
(a) Identify the maintenance issue with typing 3.14 manually in every calculation.
[2]

(b) Write a single line of code to declare 3.14 as a constant named PI, and write one example line showing how to use it in a calculation.
[2]
END OF QUESTION PAPER