Bird
0
0

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

medium📝 Predict Output Q4 of 15
Raspberry Pi - Platform
What will be the output of this Python code on Raspberry Pi?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, True)
print(GPIO.input(17))
A1
BTrue
CGPIO.OUT
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.output and GPIO.input behavior

    Setting pin 17 output to True means the pin is HIGH. Reading it with GPIO.input(17) returns 1 for HIGH.
  2. Step 2: Confirm print output type

    The GPIO.input() returns integer 1 or 0, so print outputs 1.
  3. Final Answer:

    1 -> Option A
  4. Quick Check:

    GPIO.input after output True = 1 [OK]
Quick Trick: GPIO.input returns 1 for HIGH, 0 for LOW [OK]
Common Mistakes:
  • Expecting True instead of 1
  • Confusing output with input function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes