Your question is Walk Through a Python Script. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Turck builds industrial sensors, and its QA team runs an automated pass or fail check against every sensor reading before a batch ships. You're handed this Python script during a QA engineering interview and asked to walk through it end to end.
import time
def run_sensor_checks(readings, thresholds, retries=[]):
results = []
for sensor_id, value in readings.items():
threshold = thresholds.get(sensor_id, thresholds["default"])
attempt = 0
passed = False
while attempt < 3:
if value <= threshold:
passed = True
break
attempt += 1
time.sleep(0.1)
retries.append(sensor_id)
results.append({
"sensor_id": sensor_id,
"value": value,
"threshold": threshold,
"passed": passed,
"attempts": attempt + 1
})
return results
def summarize(results):
total = len(results)
failed = [r for r in results if not r["passed"]]
pass_rate = (total - len(failed)) / total * 100
return {
"total": total,
"failed": len(failed),
"pass_rate": round(pass_rate, 1)
}
Explain what run_sensor_checks and summarize do, in the order they execute. As you walk through it, call out anything you would flag in a code review, including behavior that only shows up on repeated calls or on edge-case inputs, since that's exactly what a QA engineer is expected to catch before this ships.