Bird
0
0

Examine this code snippet:

medium📝 Debug Q7 of 15
Raspberry Pi - GPIO Basics with Python
Examine this code snippet:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
try:
    GPIO.setup(17, GPIO.OUT)
    GPIO.output(17, true)
finally:
    pass

What is the issue preventing proper GPIO cleanup?
AThe <code>finally</code> block does not call <code>GPIO.cleanup()</code>
BThe <code>GPIO.output</code> uses lowercase <code>true</code> instead of <code>True</code>
CThe GPIO mode is set incorrectly
DThe <code>try</code> block is missing an <code>except</code> clause
Step-by-Step Solution
Solution:
  1. Step 1: Check cleanup call

    The finally block is empty and does not call GPIO.cleanup().
  2. Step 2: Identify impact

    Without calling cleanup, GPIO pins remain configured, causing issues.
  3. Step 3: Note other errors

    While true should be True, the main issue is missing cleanup.
  4. Final Answer:

    The finally block does not call GPIO.cleanup() -> Option A
  5. Quick Check:

    Cleanup must be explicitly called [OK]
Quick Trick: Always call GPIO.cleanup() in finally [OK]
Common Mistakes:
  • Ignoring missing cleanup call
  • Confusing Python boolean case
  • Assuming try-finally without cleanup is enough

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes