Question: We have provided two problems for you to work with. For each problem, you are asked to carry out the six steps listed below. Provide
We have provided two problems for you to work with. For each problem, you are asked to carry out the six steps listed below.
-
Provide a high-level decomposition. This should do no more than break the problem into the main sub-problems. It is a description of what the solution needs to do, without going into the detail of how it will be done. As a rather fanciful example, if you were planning a mission to collect rock samples from the Moon a high-level decomposition could be:
> Collect Moon rocks
>> Fly to Moon
>> Land
>> Collect rock samples
>> Return to Earth
As you see, this leaves out all the detail of things like distances and velocities and just gives the big picture.
Note: this is just an example. Your decompositions will be very different because you are concerned with different problems, but we hope the example gives a feel for the level of detail appropriate in a high-level decomposition.
- Say what the inputs and outputs of the problem are.
- Write two tests for the problem. Present the tests in a table, with a column for each input and output, and an extra column with a brief explanation of why you selected each test (as is done in Block 2 Part 2 Activity 2.10, for example).
- Identify which of the TM112 pattern or patterns should be applied to the solution of the problem. State clearly the name of the pattern and the pattern number: for example, List generation Pattern 2.2. A list of all the patterns can be found in the Problem solving and Python quick reference.
- Write an algorithm for the problem by instantiating the pattern you have chosen.
- Implement your algorithm as Python code. This must match the steps of your algorithm and you should use comments in the code to make it clear how the two correspond. Marks will be lost if the program does not follow the algorithm.
You should aim to use only the Python features that are introduced in the module. If you decide to use techniques or language features that TM112 does not cover, you must give a justification for your decisions, otherwise marks will be lost.
The problems
The normal body temperature of dogs is between 38.3 and 39.2 degrees Celsius. Imagine a vet has measured the body temperatures of a number of dogs and recorded the results in a list. For example, the temperatures might be:
[39.3, 38.1, 38.5, 38.4, 39.1, 38.9, 39.5, 39.2, 38.6, 38.0]
-
a.Starting with a list of temperatures like the one above, create a new list according to the following rules:
- Where a temperature is lower than 38.3, add L to the new list.
- Where a temperature is normal (i.e. between 38.3 and 39.2 inclusive), add N to the new list.
- Where a temperature is higher than 39.2, add H to the new list.
For example, the list above would give the following:
['H', 'L', 'N', 'N', 'N', 'N', 'H', 'N', 'N', 'L']
(9 marks)
-
b.Starting with a list of temperatures like the one above, find what percentage of the temperatures lie within the normal range, rounding the answer to one decimal place.
For example, the list above contains 10 temperatures, of which 6 are in the normal range, a percentage of 60.0.
(The Python round function was introduced in 1.2.3 of Block 1 Part 1.)
(9 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
