Bird
0
0

Identify the error in this code that tries to blink an LED on pin 5:

medium📝 Debug Q14 of 15
Raspberry Pi - gpiozero Library

Identify the error in this code that tries to blink an LED on pin 5:

from gpiozero import LED
from time import sleep

led = LED(5)
led.blink(on_time=0.5, off_time=0.5)
sleep(2)
led.off()
AMissing <code>led.on()</code> before blink
BShould call <code>led.close()</code> to clean GPIO
CNo error; code works correctly
Dblink() method requires a <code>times</code> argument
Step-by-Step Solution
Solution:
  1. Step 1: Review the code for GPIO cleanup

    The code blinks the LED and turns it off but does not release GPIO resources.
  2. Step 2: Identify missing cleanup step

    Proper practice is to call led.close() to free GPIO pins after use.
  3. Final Answer:

    Should call led.close() to clean GPIO -> Option B
  4. Quick Check:

    Always close GPIO pins after use [OK]
Quick Trick: Always close() LEDs to free GPIO pins [OK]
Common Mistakes:
  • Thinking blink() needs on() first
  • Assuming blink() requires times argument
  • Ignoring GPIO cleanup after program

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes