CS 115 Lab 11 - Strings and Lists
90 points
Due by Monday, April 19, at end of lab period
Submit your team's work with the Canvas link.
Educational goals of this lab - verify that every student can
- write sentinel logic
- handle multiple pieces of data on one line
- manipulate strings and lists
- use a counter and an accumulator
- if, loops control structures
INSTRUCTIONS:
(80 points) Team Problem: Process patient temperatures
-
Write a program that will accept input about patients and their temperatures
from the user until they press enter by itself.
-
The input is of the form: a patient number, then three temperature readings
(assumed to be Fahrenheit, and assumed to be human readings) all on the same line.
All data is delimited by any amount of whitespace.
Your program can assume there is always this much data (4 pieces) on each line.
-
The program finds the average of the 3 temperatures.
The program creates a list in which each entry is a 2-element list, the patient number
and this average. It looks like [['12345', 98.6], ['45214', 101.0], ['23145', 96.5], ...]
-
When the input is completed, then the program prints out the information in the
new list, along with a diagnosis based on these rules:
if the temperature average is higher than 98.7
the diagnosis is "fever"
if the temperature is less than 95.0,
the diagnosis is "chilled"
if the temperature is inside the range 95.0 to 98.7,
there is no diagnosis.
NOTE that the diagnosis is NOT part of the list described above. It is
only printed as needed during the output process.
- After the printout, the program should also produce counts of how many patients were processed,
how many had the "fever" diagnosis, and how many have the "chilled" diagnosis,
and what percentage each of those is of the whole number of patients.
(15 points) Testing
- You can use the sample outputs below for test cases.
- Write up one more test case with 2 patients. One patient should have
the same temperature three times, with an average that is a fever;
the other patient should have the same temperature three times, with an
average that is a chill.
Put these at the end of the program in a comment, appropriate organized.
(15 points) Design / Documentation
- The 3 P's as usual for the program.
- Document each control structure - what is its job?
(60 points) Implementation
- If you want the length of a list, use the len function, you do NOT
need a separate counter.
- The patient number should NOT be cast as an integer.
You are not doing any arithmetic with it. It is a label, not a quantity.
Leave it as a string. Another reason for leaving it as a string is
if the number starts with a zero, it will not be lost.
- The program should work no matter how many or how few patients are input.
Make sure your code never divides by zero.
- The logic for printing the diagnosis should only have TWO lines
in each branch of your logic. Do not print out the patient ID or the average
three times.
- The average temperature should be output formatted with 2 places.
The percentages should be output formatted with 1 place.
-
Sample output
Press Enter to stop entering data
Enter patient number and 3 temps separated by whitespace: 11111 93.5 94.0 97.0
Enter patient number and 3 temps separated by whitespace: 22222 98.6 98.6 98.7
Enter patient number and 3 temps separated by whitespace: 33333 99.0 99.0 99.0
Enter patient number and 3 temps separated by whitespace: 44444 101.0 96.7 98.9
Enter patient number and 3 temps separated by whitespace: 55555 98.5 98.5 98.6
Enter patient number and 3 temps separated by whitespace:
PT AVG Diagnosis
11111 94.83 chilled
22222 98.63
33333 99.00 fever
44444 98.87 fever
55555 98.53
There were 5 patients processed
2 had a fever (40.0%)
1 had a low temperature (20.0%)
-
Another Sample Output (no patients) (note: no percentages output)
Press Enter to stop entering data
Enter patient number and 3 temps separated by whitespace:
PT AVG Diagnosis
There were 0 patients processed
-
Another Sample Output
Press Enter to stop entering data
Enter patient number and 3 temps separated by whitespace: 99999 98.0 97.0 97.0
Enter patient number and 3 temps separated by whitespace: 31345 97.0 97.5 97.0
Enter patient number and 3 temps separated by whitespace: 12345 98.0 97.9 98.0
Enter patient number and 3 temps separated by whitespace:
PT AVG Diagnosis
99999 97.33
31345 97.17
12345 97.97
There were 3 patients processed
0 had a fever (0.0%)
0 had a low temperature (0.0%)
- Submit your finished program with the Canvas link. Call it Lab11.py