Bird
0
0

How can you modify this code to play a melody repeatedly until stopped?

hard📝 Application Q9 of 15
Raspberry Pi - gpiozero Library
How can you modify this code to play a melody repeatedly until stopped? ```python from gpiozero import TonalBuzzer from time import sleep buzzer = TonalBuzzer(12) buzzer.play('E4:1 F4:1 G4:1') sleep(3) buzzer.stop() ```
AAdd repeat=True parameter to play method.
BCall buzzer.play() inside a while True loop.
CUse buzzer.play('E4:1 F4:1 G4:1', loop=True)
DUse buzzer.play('E4:1 F4:1 G4:1') without sleep.
Step-by-Step Solution
Solution:
  1. Step 1: Check TonalBuzzer play method options

    play() supports a loop parameter to repeat melody automatically.
  2. Step 2: Identify correct way to loop melody

    Use buzzer.play('E4:1 F4:1 G4:1', loop=True) uses loop=True to repeat melody until stopped.
  3. Final Answer:

    Use buzzer.play('E4:1 F4:1 G4:1', loop=True) -> Option C
  4. Quick Check:

    Loop parameter repeats melody [OK]
Quick Trick: Use loop=True in play() to repeat melody [OK]
Common Mistakes:
  • Using while True loop incorrectly
  • Assuming repeat=True exists
  • Omitting sleep causes no sound

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes