Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using python 3 to wirte a function: The number in this list \"(thresholds1])\" r

ID: 3587414 • Letter: U

Question

Using python 3 to wirte a function:

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

Explanation / Answer

month_from_value = {}
month_from_value[0] = 'JAN'
month_from_value[1] = 'FEB'
month_from_value[2] = 'MAR'
month_from_value[3] = 'APR'
month_from_value[4] = 'MAY'
month_from_value[5] = 'JUN'
month_from_value[6] = 'JUL'
month_from_value[7] = 'AUG'
month_from_value[8] = 'SEP'
month_from_value[9] = 'OCT'
month_from_value[10] = 'NOV'
month_from_value[11] = 'DEC'

def test_alert(thresholds, counts, num_months=2):
count = 0
for i in range(0, len(counts)):
if counts[i] > thresholds[i]:
count += 1
if count == num_months:
return month_from_value[i]
else:
count = 0
return -1

thresholds = [[], []]
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]

print(thresholds[1])
print(test_alert(thresholds[1], [0,0,4]))
print(test_alert(thresholds[1], [0,10,23,30]))
print(test_alert(thresholds[1], [0,10,23,30], num_months=3))
print(test_alert(thresholds[1], [10,1 ,5,45,93]))

# code link: https://paste.ee/p/TaEdJ

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote