Twa kɔ nsɛm atitiriw so
Log in
Sign up for FREE
arrow_back
Laabri

Debugging Lab: Smart Greenhouse Challenge

star
star
star
star
star
Last updated 16 days ago
12 Nsɛmmisa
Akwankyerɛ

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.

Ɛhia
1
CCR.R.1
D2.His.14.3-5
+6
Ɛhia
3
D2.His.14.3-5
D4.2.3-5
+3
Ɛhia
1
D2.His.14.3-5
D4.2.3-5
+2
Ɛhia
4
D2.His.14.3-5
D4.2.3-5
+6
Ɛhia
1
CCR.R.1
D2.His.14.3-5
+6
Ɛhia
1
D2.His.14.3-5
D4.2.3-5
RST.6-8.4
Ɛhia
1
CCR.L.4
CCR.L.6
+3
Ɛhia
2
D2.His.14.3-5
D4.2.3-5
RST.6-8.3
Ɛhia
2
D4.2.3-5
RST.6-8.3
Asemmisa {{asɛmmisaAhyɛnsode}}
1.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
2.

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.

Asemmisa {{asɛmmisaAhyɛnsode}}
3.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
4.

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.

Asemmisa {{asɛmmisaAhyɛnsode}}
5.

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.

Asemmisa {{asɛmmisaAhyɛnsode}}
6.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
7.

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?

Ɛhia
1
Asemmisa {{asɛmmisaAhyɛnsode}}
8a.

Part 1 — Trace the code

moisture = 24
if moisture < 30:
    water_seconds = 10
water_seconds = 0
print(water_seconds)

What value is printed?

D4.2.3-5
D4.5.3-5
RST.6-8.3
Ɛhia
1
D4.2.3-5
D4.5.3-5
RST.6-8.3
Ɛhia
2
Asemmisa {{asɛmmisaAhyɛnsode}}
8c.

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.

D4.2.3-5
D4.5.3-5
RST.6-8.3
Asemmisa {{asɛmmisaAhyɛnsode}}
9.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
10.

Lab 4 — Design useful tests

A greenhouse vent should open at 30°C or above. Which two tests best check the threshold behavior?

Asemmisa {{asɛmmisaAhyɛnsode}}
8b.

Which change best fixes the logic error so the controller prints 10 when soil moisture is below 30 and 0 otherwise?