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(20, GPIO.OUT)
state = GPIO.input(20)
print(state)
AGPIO.input function is misspelled
BPin 20 is set as output but read as input
CGPIO.setmode is missing
DPin number 20 does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Check pin setup mode

    Pin 20 is set as output with GPIO.OUT.
  2. Step 2: Check pin reading method

    GPIO.input reads input pins only; reading output pin state this way is incorrect.
  3. Final Answer:

    Pin 20 is set as output but read as input -> Option B
  4. Quick Check:

    Read input only from pins set as input [OK]
Quick Trick: Only read input from pins set as input [OK]
Common Mistakes:
  • Reading output pin with GPIO.input
  • Misspelling GPIO functions
  • Ignoring pin mode setup
  • Assuming all pins exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes