Bird
0
0

Identify the error in this Raspberry Pi Python code snippet for controlling an LED:

medium📝 Debug Q6 of 15
Raspberry Pi - LED and Button Projects
Identify the error in this Raspberry Pi Python code snippet for controlling an LED:
GPIO.setmode(GPIO.BCM)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, HIGH)
AGPIO.setup is missing pin number
BNo error; code is correct
CGPIO.setmode should be called after output
DHIGH is not defined; should be GPIO.HIGH
Step-by-Step Solution
Solution:
  1. Step 1: Check GPIO.output parameters

    The second argument must be GPIO.HIGH or GPIO.LOW, not just HIGH.
  2. Step 2: Verify code correctness

    Using HIGH alone causes a NameError because it's undefined.
  3. Final Answer:

    HIGH is not defined; should be GPIO.HIGH -> Option D
  4. Quick Check:

    Use GPIO.HIGH, not HIGH alone [OK]
Quick Trick: Always prefix HIGH/LOW with GPIO. [OK]
Common Mistakes:
  • Forgetting GPIO. prefix
  • Calling setmode after output
  • Missing pin number in setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes