Question
Using python 3 to wirte a function: Note: The number in this list (thresholds1]) represents how many people get involved in 12 months respectively. 1st:
Using python 3 to wirte a function:
Note:
The number in this list "(thresholds1])" represents how many people get involved in 12 months respectively.
1st:
>>> test_alert(thresholds[1], [0,0,4]) -1
Because 0,0 or 0,4 not exceed 0,1.5 or 1.5,11.6 continuously , so return -1
2nd:
>>> test_alert(thresholds[1], [0,10,23,30]) 'MAR'
Becasuse 10,23 exceed 1.5 ,11.6 continuously so return MAY( Because 23 means may)
3rd:
>>> test_alert(thresholds[1], [0,10,23,30], num_months=3) -1
Since num_month = 3, we need consider 3 month together.
Also, 0,10,23 and 10,23,30 did not exceed 0.0, 1.5,11.6 and 1.5,11.6,34.4 continusly , so return -1
Write a function test_alert(thresholds , counts, num_months=2) that takes as input a list of monthly thresholds, a list of monthly case counts for the year to date, and an optional parameter that specifies the number of consecutive months that the threshold must be exceeded before an alert is triggered. Thresholds refers to the output from calculate_alert_levels (aligned_counts ). The function should return the month that the alert is triggered, if the threshold has be exceeded for num_months, or -1 if no alert has been triggered so far. Assumptions You can assume that the length of counts is always less than the length of thresholds. >>> print (thresholds [1]) [0.0, 1.5, 11.6, 34.4, 89.6, 139.2, 81.6, 73.2, 29.4, 11.7, 0.0, 0.0] >>> test_alert(thresholds [1], [0,0,4]) >>> test_alert(thresholds [1], [0, 10, 23,30]) MAR >>> test_alert(thresholds [1], [0, 10,23,301, num_months=3) >>> test_alert(thresholds [1], [10, 1,5,45,93]) MAY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started