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