A marine biologist writes a program to calculate and print the total swimming depth (in meters) recorded for Shark 5 over 8 hourly intervals (represented by indices 0 to 7) from a 2D array called depthData.
totalDepth = 0
totalDepth = totalDepth + depthData[5, 0]
totalDepth = totalDepth + depthData[5, 1]
totalDepth = totalDepth + depthData[5, 2]
totalDepth = totalDepth + depthData[5, 3]
totalDepth = totalDepth + depthData[5, 4]
totalDepth = totalDepth + depthData[5, 5]
totalDepth = totalDepth + depthData[5, 6]
totalDepth = totalDepth + depthData[5, 7]
print(totalDepth)
Refine the program to make it more efficient by using a loop. Write the refined version of the algorithm.
You must use either:
Practise OCR GCSE Computer Science Designing, creating and refining algorithms with exam-style questions for GCSE Computer Science. 50 questions, matched to the OCR GCSE Computer Science (J277) specification and written in Component 01 and Component 02 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.