4Hard
0/15

An environmental monitoring station uses a one-dimensional list to record the pH levels of a river. The pH level is measured four times a day (every six hours). This data needs to be saved to an external CSV file where each line of the file represents one day of monitoring (exactly four pH readings).

An existing Python program contains the following data structure:

ph_levels = [
    7.2, 7.15, 6.9, 7.05,
    6.8, 6.75, 6.6, 6.55,
    7.1, 7.3, 7.25, 7.4,
    6.95, 6.85, 6.9, 7.0,
    7.12, 7.18, 7.22, 7.15,
    6.85, 6.9, 6.75, 6.7
]

Write a program to meet these requirements:

  • Create or overwrite a comma-separated value (CSV) text file named RIVER_PH.CSV
  • Write lines to the file, with each line holding four pH readings representing a single day
  • Process all the readings stored in the ph_levels data structure

Here is the expected content of the file RIVER_PH.CSV:

7.2,7.15,6.9,7.05
6.8,6.75,6.6,6.55
7.1,7.3,7.25,7.4
6.95,6.85,6.9,7.0
7.12,7.18,7.22,7.15
6.85,6.9,6.75,6.7

Do not add any additional functionality to your code.

Use comments, white space, indentation, and meaningful variable names to make the program readable.

[15]

Input/output Questions

Practise Edexcel GCSE Computer Science Input/output with exam-style questions for GCSE Computer Science. 29 questions covering Accepting and responding to user input, Reading and writing CSV text files, Implementing validation, and Implementing authentication, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 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.

PreviousNext

Input/output Questions

  1. GCSE
  2. /Computer Science
  3. /Input/output