Bird
0
0

What will be the output of this Python code on a Raspberry Pi?

medium📝 Predict Output Q4 of 15
Raspberry Pi - GPIO Basics with Python
What will be the output of this Python code on a Raspberry Pi?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
print(GPIO.input(18))
A1
B0
CGPIO.HIGH
DError: Cannot read output pin
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO setup and output

    Pin 18 is set as output and then set to HIGH (which means 1).
  2. Step 2: Reading the pin state

    GPIO.input(18) reads the pin state; since it was set HIGH, it returns 1.
  3. Final Answer:

    1 -> Option A
  4. Quick Check:

    GPIO.output HIGH read = 1 [OK]
Quick Trick: Output HIGH pin reads as 1 in GPIO input [OK]
Common Mistakes:
  • Thinking output pins cannot be read
  • Confusing HIGH with 0
  • Expecting string instead of integer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes