0
0
Raspberry Piprogramming~20 mins

Automated plant watering system in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Automated Plant Watering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this soil moisture check?

Consider this Python code snippet that reads a soil moisture sensor value and decides whether to water the plant.

moisture = 350
if moisture < 300:
    print("Watering plant")
else:
    print("Soil is moist enough")

What will this code print?

Raspberry Pi
moisture = 350
if moisture < 300:
    print("Watering plant")
else:
    print("Soil is moist enough")
ASoil is moist enough
BError: moisture sensor not found
CNo output
DWatering plant
Attempts:
2 left
💡 Hint

Think about the condition: is 350 less than 300?

Predict Output
intermediate
1:30remaining
What does this pump control code print?

This code controls a water pump based on a boolean variable pump_on. What is the output?

pump_on = False
if pump_on:
    print("Pump is running")
else:
    print("Pump is off")
Raspberry Pi
pump_on = False
if pump_on:
    print("Pump is running")
else:
    print("Pump is off")
APump status unknown
BPump is running
CPump is off
DError: pump_on not defined
Attempts:
2 left
💡 Hint

Remember that False means the condition is not true.

🔧 Debug
advanced
2:00remaining
Why does this watering loop run forever?

Look at this code snippet that should water the plant once when soil is dry, but it keeps watering endlessly. What is the cause?

while True:
    moisture = 250
    if moisture < 300:
        print("Watering plant")
    else:
        print("Soil is moist enough")
Raspberry Pi
while True:
    moisture = 250
    if moisture < 300:
        print("Watering plant")
    else:
        print("Soil is moist enough")
AThe else block is missing a break statement
BThe moisture value never changes inside the loop
CThe print statement causes the loop to restart
DThe loop condition is wrong, should be while moisture < 300
Attempts:
2 left
💡 Hint

Think about what happens to the moisture value each time the loop runs.

📝 Syntax
advanced
1:30remaining
Which option has correct syntax to read sensor and water plant?

Choose the code snippet that correctly reads a moisture sensor and waters the plant if dry.

A
moisture = read_sensor()
if moisture &lt; 300:
    water_plant()
B
moisture = read_sensor()
if moisture &lt; 300
    water_plant()
C
moisture = read_sensor()
if moisture &lt; 300:
water_plant()
D
moisture = read_sensor()
if moisture &lt; 300:
    water_plant
Attempts:
2 left
💡 Hint

Remember Python needs a colon and indentation for blocks.

🚀 Application
expert
2:00remaining
How many times will the pump run in this code?

This code runs a watering pump based on sensor readings in a list. How many times will it print "Pump running"?

moisture_readings = [320, 280, 290, 310, 270]
pump_runs = 0
for moisture in moisture_readings:
    if moisture < 300:
        print("Pump running")
        pump_runs += 1
print(pump_runs)
Raspberry Pi
moisture_readings = [320, 280, 290, 310, 270]
pump_runs = 0
for moisture in moisture_readings:
    if moisture < 300:
        print("Pump running")
        pump_runs += 1
print(pump_runs)
A4
B2
C5
D3
Attempts:
2 left
💡 Hint

Count how many values in the list are less than 300.