Bird
0
0

What will be the output behavior of this code snippet?

medium📝 Predict Output Q13 of 15
Raspberry Pi - gpiozero Library
What will be the output behavior of this code snippet?
from gpiozero import PWMLED
import time
led = PWMLED(17)
led.brightness = 0.2
time.sleep(2)
led.brightness = 0.8
time.sleep(2)
led.off()
ALED glows dimly for 2 seconds, then brightly for 2 seconds, then turns off
BLED glows brightly for 2 seconds, then dimly for 2 seconds, then turns off
CLED stays off the whole time
DCode causes an error because brightness is set incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Analyze brightness settings

    First brightness is 0.2 (dim), then after 2 seconds it changes to 0.8 (bright).
  2. Step 2: Understand timing and off command

    Each brightness level lasts 2 seconds, then LED is turned off.
  3. Final Answer:

    LED glows dimly for 2 seconds, then brightly for 2 seconds, then turns off -> Option A
  4. Quick Check:

    Brightness changes 0.2 to 0.8 then off = A [OK]
Quick Trick: Brightness values control glow level over time [OK]
Common Mistakes:
  • Mixing order of brightness values
  • Thinking brightness values cause errors
  • Assuming LED stays on after off()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes