Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Raspberry Pi - GPIO Basics with Python
Identify the error in this code snippet:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
GPIO.cleanup()
ANo error, code is correct
BGPIO.cleanup() called before setting pin mode
CPin 18 is not a valid BCM pin
DGPIO.output called with invalid value
Step-by-Step Solution
Solution:
  1. Step 1: Review each line for correctness

    Import, setmode to BCM, setup pin 18 as output, set output HIGH, then cleanup.
  2. Step 2: Confirm pin 18 is valid BCM pin

    Pin 18 is a valid BCM pin number on Raspberry Pi.
  3. Step 3: Check function calls and order

    All function calls are in correct order and use valid parameters.
  4. Final Answer:

    No error, code is correct -> Option A
  5. Quick Check:

    Code runs without error = A [OK]
Quick Trick: Check pin numbers and function order carefully [OK]
Common Mistakes:
  • Calling cleanup too early
  • Using invalid pin numbers
  • Passing wrong values to output()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes