Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
Raspberry Pi - gpiozero Library
Identify the error in this code:
from gpiozero import LED
led = LED(18)
led.turn_on()
AMethod turn_on() does not exist
BLED class cannot be created on pin 18
CMissing parentheses in LED(18)
DImport statement is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check method names in LED class

    The LED class uses on() and off() methods; turn_on() is not a valid method.
  2. Step 2: Verify other parts of the code

    Pin 18 is valid, parentheses are correct, and import is correct.
  3. Final Answer:

    Method turn_on() does not exist -> Option A
  4. Quick Check:

    Use on() method, not turn_on() [OK]
Quick Trick: Use on() to turn LED on, not turn_on() [OK]
Common Mistakes:
  • Using turn_on() instead of on()
  • Thinking pin 18 is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes