Bird
0
0

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

medium📝 Predict Output Q13 of 15
Raspberry Pi - GPIO Basics with Python
What will be the output of this Python code snippet on a Raspberry Pi?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, true)
print(GPIO.input(17))
Atrue
Bfalse
CError
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Check for syntax/runtime errors

    GPIO.output(17, true) fails because 'true' is undefined in Python (use True).
  2. Step 2: Confirm program behavior

    NameError occurs before print executes, so output is Error.
  3. Final Answer:

    Error -> Option C
  4. Quick Check:

    'true' not defined -> NameError [OK]
Quick Trick: Python booleans: True/False (capitalized); 'true' -> NameError [OK]
Common Mistakes:
  • Using lowercase 'true' instead of True
  • Expecting GPIO.input to return False after output high
  • Confusing GPIO.BCM numbering with physical pins

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes