A researcher writes a program to calculate and print the total rainfall (in mm) recorded by Sensor 3 over 7 days (represented by indices 0 to 6) from a 2D array called rainfallData.
totalRain = 0
totalRain = totalRain + rainfallData[3, 0]
totalRain = totalRain + rainfallData[3, 1]
totalRain = totalRain + rainfallData[3, 2]
totalRain = totalRain + rainfallData[3, 3]
totalRain = totalRain + rainfallData[3, 4]
totalRain = totalRain + rainfallData[3, 5]
totalRain = totalRain + rainfallData[3, 6]
print(totalRain)
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.