Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
Raspberry Pi - gpiozero Library
Find the bug in this code:
from gpiozero import PWMLED
led = PWMLED(19)
led.value = -0.3
print(led.value)
Aled.value remains -0.3 and prints -0.3
BCode raises ValueError on negative value
CSyntaxError due to invalid assignment
DNegative brightness is set to 0.0 internally
Step-by-Step Solution
Solution:
  1. Step 1: Understand PWMLED value limits

    Brightness below 0.0 is clamped to 0.0 internally.
  2. Step 2: Check printed output

    Assigning -0.3 sets brightness to 0.0; print outputs 0.0.
  3. Final Answer:

    Negative brightness is set to 0.0 internally -> Option D
  4. Quick Check:

    Negative values clamp to 0.0 = C [OK]
Quick Trick: Brightness below 0.0 clamps to 0.0 automatically [OK]
Common Mistakes:
  • Expecting error on negative value
  • Assuming negative value is accepted
  • Confusing with syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes