Skip to content

Course home

Sign up

Input/output

EasyMediumHard
123
Question 1

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]
Markscheme

Input/output Questions

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

25 exam-style questions on Edexcel GCSE Computer Science Input/output, covering Accepting and responding to user input, Reading and writing CSV text files, Implementing validation, and Implementing authentication. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank