Bird
0
0

Identify the error in this Python code for Raspberry Pi GPIO:

medium📝 Debug Q6 of 15
Raspberry Pi - Platform
Identify the error in this Python code for Raspberry Pi GPIO:
import RPi.GPIO as GPIO
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, True)
ANo error, code is correct
BWrong pin number 18
CMissing GPIO.setmode() before setup
DGPIO.output() should be called before setup
Step-by-Step Solution
Solution:
  1. Step 1: Check required setup sequence for GPIO

    Before calling GPIO.setup(), you must set the pin numbering mode with GPIO.setmode().
  2. Step 2: Identify missing function

    The code misses GPIO.setmode(GPIO.BCM) or GPIO.setmode(GPIO.BOARD).
  3. Final Answer:

    Missing GPIO.setmode() before setup -> Option C
  4. Quick Check:

    GPIO.setmode required before setup [OK]
Quick Trick: Always call GPIO.setmode() before setup [OK]
Common Mistakes:
  • Skipping GPIO.setmode causes runtime error
  • Calling output before setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes