Bird
0
0

Find the mistake in this code that causes an error:

medium📝 Debug Q7 of 15
Raspberry Pi - GPIO Basics with Python
Find the mistake in this code that causes an error:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.output(16, GPIO.HIGH)
AGPIO.setup() missing for pin 16
BGPIO.setmode() called incorrectly
CGPIO.output() requires only one argument
DPin number 16 is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check if pin 16 is configured

    GPIO.setup() must be called to set pin 16 as output before using GPIO.output().
  2. Step 2: Identify missing setup call

    The code calls GPIO.output() without prior setup, causing runtime error.
  3. Final Answer:

    GPIO.setup() missing for pin 16 -> Option A
  4. Quick Check:

    Always setup pin mode before output [OK]
Quick Trick: Always call GPIO.setup(pin, GPIO.OUT) before GPIO.output() [OK]
Common Mistakes:
  • Skipping GPIO.setup() call
  • Misusing GPIO.setmode()
  • Assuming GPIO.output works without setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes