Question: Python Could u teach me it I do not know what kind of error in it Complete the calculate_average_positive_temperature() function that takes two parameters: 1.





Python Could u teach me it I do not know what kind of error in it
Complete the calculate_average_positive_temperature() function that takes two parameters: 1. An integer list of temperatures called temperature_list. 2. 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 O 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: 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 Average 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_list [-13, -14, -17, -9, 5, 1, 2, 3, 4] print("Average temperature:", calculate_average_positive_temperature (temperature_list, 5)) 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 O 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: Result [23, 12, 13, -5, -13, 7, 31, -2, 1, 4, 5] perature:", calculate_average_positive_temperature (temperature_list, 30)) Average temperature: 13.75 Average temperature: 0.0 [-13, -14, -17, -9, 5, 1, 2, 3, 4] perature:", calculate_average_positive_temperature (temperature_list, 5)) Answer: (penalty regime: 0 %) Reset answer 1 def calculate_average_positive_temperature(temperature list, sentinel_value): 2. x = 0 3 for element in temperature_list: 5v if element 0: 7 x = x + element 8 n = n + 1 9 else: 10 if n ! =, 0: z = x / n 12 round(2, 2) 13 return z 14 else: 15 0.0 16 Z return Z 18 1 Precheck Check Test E> temperature_list [23, 12, 13, -5, -13, 7, 31, -2, 1, 4, 5] print("Average temperature:", calculate_average_positive_temperature (temperature_list, 30)) temperature_list [-13, -14, -17, -9, 5, 1, 2, 3, 4] print("Average temperature:", calculate_average_positive_temperature (temperature_list, 5)) AV Your code failed one or more hidden tests. Your code must pass all tests to earn any marks. Try again. Incorrect Marks for this submission: 0.00/5.00 s page
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
