158k views
1 vote
Write another routine that stores the temperatures taken over a three-hour period in an array. This routine should output the highest and lowest temperatures and calculate the difference between these temperatures.

1 Answer

5 votes

Final answer:

To monitor temperatures over a three-hour period, store the readings in an array, find the highest and lowest values, and then calculate the temperature difference. This routine provides min, max, and range of the temperature data.

Step-by-step explanation:

To write a routine that stores temperatures taken over a three-hour period in an array and outputs the highest and lowest temperatures and calculates the difference between them, consider the following approach:

  • Initiate an array to store temperature readings.
  • Collect temperature data at regular intervals over three hours and store each value in the array.
  • Determine the highest and lowest temperature recorded.
  • Calculate the difference between the highest and lowest temperatures.

For example:

  1. Create array: temperatures = []
  2. Record temperatures: temperatures.append(measured_temp)
  3. Find highest temp: max_temp = max(temperatures)
  4. Find lowest temp: min_temp = min(temperatures)
  5. Calculate difference: temp_difference = max_temp - min_temp

Output the highest, lowest temperatures, and the difference.

User Ivan Correa
by
7.2k points