# Hysteresis means the decision depends partly on the previous state, preventing rapid switching near one threshold.
fan = False
for temperature in [29, 27, 25]:
if temperature > 28:
fan = True
elif temperature < 26:
fan = False
print(temperature, fan)
# Test 28 explicitly; an expected result is written before the run.
def fan_on(t):
return t > 28
for value, expected in [(27, False), (29, True)]:
print(value, expected, fan_on(value), fan_on(value) == expected)