Bird
0
0

Which code snippet correctly implements this?

hard📝 Application Q15 of 15
Raspberry Pi - LED and Button Projects
You want to create a chase LED pattern on pins 17, 18, 27, 22 where each LED lights up one after another with 0.3 seconds delay, then all turn off together. Which code snippet correctly implements this?
Afor pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.HIGH) time.sleep(0.3) for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.LOW)
Bfor pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.HIGH) time.sleep(0.3) GPIO.output(pin, GPIO.LOW)
CGPIO.output([17, 18, 27, 22], GPIO.HIGH) time.sleep(0.3) GPIO.output([17, 18, 27, 22], GPIO.LOW)
Dfor pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.LOW) time.sleep(0.3) GPIO.output([17, 18, 27, 22], GPIO.HIGH)
Step-by-Step Solution
Solution:
  1. Step 1: Understand chase pattern requirements

    Each LED lights up one by one with delay, then all turn off together.
  2. Step 2: Analyze options for correct sequence

    for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.HIGH) time.sleep(0.3) for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.LOW) lights LEDs one by one with delay, then turns all off together. for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.HIGH) time.sleep(0.3) GPIO.output(pin, GPIO.LOW) turns each LED on and off immediately, no chase. GPIO.output([17, 18, 27, 22], GPIO.HIGH) time.sleep(0.3) GPIO.output([17, 18, 27, 22], GPIO.LOW) turns all on at once, no chase. for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.LOW) time.sleep(0.3) GPIO.output([17, 18, 27, 22], GPIO.HIGH) turns LEDs off first, then all on, wrong order.
  3. Final Answer:

    for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.HIGH) time.sleep(0.3) for pin in [17, 18, 27, 22]: GPIO.output(pin, GPIO.LOW) -> Option A
  4. Quick Check:

    Sequential on + delay, then all off [OK]
Quick Trick: Turn all off after loop, not inside it [OK]
Common Mistakes:
  • Turning LEDs off immediately inside loop
  • Turning all LEDs on at once instead of sequentially
  • Reversing on/off order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes