Work through a smart-greenhouse debugging lab. Trace code, identify logic errors, select useful test cases, and evaluate a fix. Use evidence from the code and test results to explain how programmers reason through bugs. The activities are designed to be approachable across Grades 9–12, with opportunities to extend your thinking.
Lab 1 — Trace the greenhouse controller
A smart greenhouse uses this Python code:
temperature = 29
if temperature < 30:
print("Vent: CLOSED")
else:
print("Vent: OPEN")
What message is printed, and what condition is tested?
Lab 2 — Find the boundary bug
The greenhouse should switch on its fan when the temperature is at least 30 degrees. A programmer wrote:
if temperature > 30:
fan = "ON"
else:
fan = "OFF"
Test the logic at 29, 30, and 31 degrees. Which test case reveals the bug? Explain what the current code does at that value and how you would fix the condition.
Lab 3 — Trace two sensor conditions
The fan should run only if the temperature is at least 30 degrees and humidity is below 80%.
temperature = 32
humidity = 85
if temperature >= 30 and humidity < 80:
fan = "ON"
else:
fan = "OFF"
What is the final fan setting, and why?
Lab 4 — Build a boundary test plan
The greenhouse lights should be on from 06:00 through 18:00, including both endpoints. A programmer wrote:
if hour > 6 and hour < 18:
lights = "ON"
else:
lights = "OFF"
List five test inputs: before opening, at opening, during the day, at closing, and after closing. For each, predict whether the lights should be on or off. Identify the bug and propose a corrected condition.
Lab 2 — Find the boundary bug
The greenhouse should open a vent when the temperature is 30°C or higher. The code is:
if temperature > 30:
open_vent()
A test at exactly 30°C leaves the vent closed. Name the logic error in three words or fewer.
Lab 3 — Diagnose the control-logic bug
The greenhouse fan should turn on if the temperature is above 28°C or the humidity is above 70%. The current code is:
if temperature > 28 and humidity > 70:
turn_on_fan()
Which change best matches the stated rule?
Lab 4 — Choose a test that exposes the bug
The fan should run when temperature > 28 or humidity > 70. A programmer accidentally used and. Which test case is most useful for exposing that specific bug?
Part 1 — Trace the code
moisture = 24
if moisture < 30:
water_seconds = 10
water_seconds = 0
print(water_seconds)
What value is printed?
After applying that fix, choose one test input below 30 and one test input at or above 30. State the expected output for each and explain how the tests check both branches of the requirement.
Lab 4 — Design useful tests
A programmer changes the greenhouse rule so the vent should open at 30°C or above. Which two test temperatures are most useful for checking the boundary and confirming the rule behaves correctly on both sides?
Lab 4 — Design useful tests
A greenhouse vent should open at 30°C or above. Which two tests best check the threshold behavior?
Which change best fixes the logic error so the controller prints 10 when soil moisture is below 30 and 0 otherwise?