Bird
0
0

Identify the error in this Raspberry Pi watering system code snippet:

medium📝 Debug Q14 of 15
Raspberry Pi - Automation and Scheduling

Identify the error in this Raspberry Pi watering system code snippet:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
soil_moisture = 500
if soil_moisture > 400
    GPIO.output(17, GPIO.LOW)
    print("Pump OFF")
Asoil_moisture value is invalid
BMissing colon (:) after if condition
CGPIO.output should be GPIO.setup
DWrong GPIO pin number
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    Python requires a colon (:) after the if condition.
  2. Step 2: Identify missing colon error

    The code misses ':' after 'if soil_moisture > 400', causing syntax error.
  3. Final Answer:

    Missing colon (:) after if condition -> Option B
  4. Quick Check:

    if statement needs ':' = D [OK]
Quick Trick: Always put ':' after if conditions in Python [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after if
  • Confusing GPIO.output with GPIO.setup
  • Assuming pin number is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes