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:
41 exam-style questions on OCR GCSE Computer Science Designing, creating and refining algorithms. Each one has a worked solution and a mark scheme showing where the marks go.