Bird
0
0

What will be the output of this code snippet controlling an LED?

medium📝 Predict Output Q13 of 15
Raspberry Pi - gpiozero Library

What will be the output of this code snippet controlling an LED?

from gpiozero import LED
from time import sleep

led = LED(22)
led.on()
sleep(1)
led.off()
print('LED state:', led.is_lit)
ASyntaxError
BLED state: True
CLED state: None
DLED state: False
Step-by-Step Solution
Solution:
  1. Step 1: Trace the LED state changes

    The LED is turned on, then after 1 second turned off before printing.
  2. Step 2: Check the printed LED state

    After led.off(), led.is_lit is False, so output is 'LED state: False'.
  3. Final Answer:

    LED state: False -> Option D
  4. Quick Check:

    LED off means is_lit = False [OK]
Quick Trick: Check final LED state after all commands run [OK]
Common Mistakes:
  • Assuming LED stays on after off()
  • Confusing is_lit property value
  • Expecting syntax error due to sleep

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes