Bird
0
0

Identify the error in this code snippet for blinking an LED on pin 8:

medium📝 Debug Q6 of 15
Raspberry Pi - Platform
Identify the error in this code snippet for blinking an LED on pin 8:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.OUT)
while True:
    GPIO.output(8, HIGH)
    time.sleep(0.5)
    GPIO.output(8, LOW)
    time.sleep(0.5)
AGPIO.setup is missing pin mode
BHIGH and LOW are not prefixed with GPIO
Ctime.sleep is used incorrectly
DGPIO.setmode is called after setup
Step-by-Step Solution
Solution:
  1. Step 1: Check constants usage

    Constants HIGH and LOW must be used as GPIO.HIGH and GPIO.LOW.
  2. Step 2: Identify missing prefix

    The code uses HIGH and LOW without GPIO., causing a NameError.
  3. Final Answer:

    HIGH and LOW are not prefixed with GPIO -> Option B
  4. Quick Check:

    Use GPIO.HIGH and GPIO.LOW constants correctly [OK]
Quick Trick: Always prefix HIGH/LOW with GPIO [OK]
Common Mistakes:
  • Forgetting GPIO prefix
  • Misusing sleep
  • Wrong setup order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes