Complete the code to show how polling works by regularly checking a sensor value.
while True: sensor_value = read_sensor() if sensor_value [1] threshold: alert_operator() sleep(5)
Polling checks if the sensor value is greater than a threshold regularly.
Complete the code to implement report-by-exception by sending data only when it changes.
previous_value = None while True: current_value = read_sensor() if current_value [1] previous_value: send_report(current_value) previous_value = current_value sleep(5)
Report-by-exception sends data only when the current value is different from the previous one.
Fix the error in this polling loop that causes it to miss alerts.
while True: value = read_sensor() if value [1] threshold: alert_operator() sleep(5)
Using '>=' ensures alerts trigger when value equals or exceeds the threshold, avoiding missed alerts.
Fill both blanks to create a report-by-exception dictionary with sensor names and values only if value changed.
reports = {sensor: [1] for sensor, value in sensors.items() if value [2] last_values.get(sensor)}The dictionary includes sensor values where the current value differs from the last reported value.
Fill all three blanks to build a polling loop that reads sensors, updates last values, and alerts if any value exceeds threshold.
last_values = {}
while True:
readings = {sensor: read_sensor(sensor) for sensor in sensors}
for sensor, value in readings.items():
if value [1] threshold:
alert_operator(sensor, value)
last_values[[2]] = [3]
sleep(5)The loop alerts when value exceeds threshold, then updates last_values with current sensor and value.