Question: Complete the calculate_average_positive_temperature() function that takes two parameters: An integer list of temperatures called temperature_list. An integer sentinel_value. The function should calculate and return the
Complete the calculate_average_positive_temperature() function that takes two parameters:
- An integer list of temperatures called temperature_list.
- An integer sentinel_value.
The function should calculate and return the average of all the positive temperatures in temperature_list until a temperature greater than or equal to the sentinel_value is encountered. The average should be returned rounded to the nearest 2 decimal places. Some things to note:
- If a temperature that is greater than or equal to the sentinel_value is not found in temperature_list, then the average of all the positive temperatures in temperature_list should be returned.
- If there are no positive temperatures in temperature_list, or if the sentinel_value is met or exceeded prior to encountering a positive temperature, then the function should return 0.0 as the average temperature.
- A temperature of 0 should be counted as a positive temperature for the purposes of this function
Some examples of the function being called are shown below.
For example:
| Test | Result |
|---|---|
temperature_list = [23, 12, 13, -5, -13, 7, 31, -2, 1, 4, 5] print("Average temperature:", calculate_average_positive_temperature(temperature_list, 30)) | Average temperature: 13.75 |
temperature_list = [-13, -14, -17, -9, 5, 1, 2, 3, 4] print("Average temperature:", calculate_average_positive_temperature(temperature_list, 5)) | Average temperature: 0.0 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
