Bird
0
0

What will be the output of this code snippet using gpiozero?

medium📝 Predict Output Q13 of 15
Raspberry Pi - gpiozero Library
What will be the output of this code snippet using gpiozero?
from gpiozero import LED
from time import sleep
led = LED(17)
led.on()
sleep(1)
print(led.is_lit)
AFalse
BTrue
C1
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code actions

    The code imports LED, creates an LED object on pin 17, turns it on, waits 1 second, then prints if the LED is lit.
  2. Step 2: Determine the output of led.is_lit

    Since led.on() was called, led.is_lit returns True, so the printed output is True.
  3. Final Answer:

    True -> Option B
  4. Quick Check:

    LED turned on means is_lit = True [OK]
Quick Trick: led.on() sets is_lit True immediately [OK]
Common Mistakes:
  • Expecting False because of sleep
  • Thinking is_lit returns 1 or None
  • Confusing method names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes