Patients¶
A file contains a record of the body temperatures of several patients staying in a hospital. The Each line of the file corresponds to a patient and contains the name of the patient (str) followed by a number of measured temperatures (float) all separated by coma (',') . The number of dates and the number of measures for all the patients is the same. The file patients.txt contains the following example:
Josefa Marquez,37.6,38.2,38.8,38.9,38.9 Joan Oliva,36.5,36.6,36.5,36.8,36.5 Peret Manau,37.3,38.4,36.5,36.6,36.8 Josep Petit,38.2,38.1,36.5,36.8,35.9 Margarida Flor,36.7,36.5,36.9,37.5,36.2 Maria Montserrat,39.4,38.9,39.1,38.3,37.1 Lluis Perez,36.9,36.5,36.8,36.5,37.0 Puri Garcia,37.0,37.3,38.4,36.6,35.9 Joana Marques,38.2,38.1,36.5,36.8,35.9
We need to filter the patients whose average temperature is strictly greater than a given threshold.
Implement the following Python function in the module patients (file patients.py):
- filter_high_fever(pat_in, pat_out, th)``
such that
and does two things:
1. writes a file with namepat_outwith the information about the patients inpat_inwhose average temperature is strictly greater thanth. The format etails of the file is as follows:
The patients must appear in the same order as in the
pat_infile.For each patient the must be a line with the name, the average temperature rounded to 2 decimal, and h@s measures, all separated by coma (‘,’).
2. returns twointwith the number of patients processed and the number of patients filtered.
For example the call filter_high_fever('patients.txt', 'pat37.1.txt', 37.1) should return (9, 5) and create the file pat37.1.txt that contains the following text:
Josefa Marquez,38.48,37.6,38.2,38.8,38.9,38.9 Peret Manau,37.12,37.3,38.4,36.5,36.6,36.8 Josep Petit,37.1,38.2,38.1,36.5,36.8,35.9 Maria Montserrat,38.56,39.4,38.9,39.1,38.3,37.1 Joana Marques,37.1,38.2,38.1,36.5,36.8,35.9
Doctests are available at the filter_high_fever-test.txt file.