Bird
0
0

Identify the error in this Raspberry Pi reaction game code snippet:

medium📝 Debug Q14 of 15
Raspberry Pi - LED and Button Projects
Identify the error in this Raspberry Pi reaction game code snippet:
GPIO.setup(18, GPIO.OUT)
GPIO.setup(23, GPIO.IN)
GPIO.output(23, GPIO.HIGH)
# Wait for button press on pin 23
APin 23 should be set as GPIO.OUT
BGPIO.setup() missing for pin 18
CGPIO.output() used on input pin 23, which is incorrect
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check pin setup

    Pin 23 is set as input with GPIO.setup(23, GPIO.IN).
  2. Step 2: Identify incorrect usage

    GPIO.output() cannot be used on input pins; it is only for output pins.
  3. Final Answer:

    GPIO.output() used on input pin 23, which is incorrect -> Option C
  4. Quick Check:

    GPIO.output() only for output pins [OK]
Quick Trick: Use GPIO.output only on output pins [OK]
Common Mistakes:
  • Trying to write output on input pins
  • Forgetting to setup pins before use
  • Assuming no error when pin modes mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes