Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Raspberry Pi - GPIO Basics with Python
Identify the error in this code snippet:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, "OUT")
GPIO.output(11, True)
GPIO.cleanup()
ACalling GPIO.cleanup() before output.
BUsing string "OUT" instead of GPIO.OUT in setup.
CMissing GPIO.setwarnings(False) before setup.
DNot importing time module for delays.
Step-by-Step Solution
Solution:
  1. Step 1: Check GPIO.setup() syntax

    The direction argument must be GPIO.OUT or GPIO.IN, not a string like "OUT".
  2. Step 2: Verify other lines

    GPIO.setwarnings() is optional, cleanup is correctly called last, and time module is not needed here.
  3. Final Answer:

    Using string "OUT" instead of GPIO.OUT in setup. -> Option B
  4. Quick Check:

    Pin direction must be GPIO.OUT, not "OUT" [OK]
Quick Trick: Use GPIO.OUT constant, not string "OUT" [OK]
Common Mistakes:
  • Passing pin direction as string
  • Calling cleanup too early
  • Forgetting to import GPIO properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes