Challenge - 5 Problems
Buzzer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output when the buzzer is activated?
Consider the following Python code using the gpiozero library on a Raspberry Pi. What will be printed when the buzzer is turned on and off?
Raspberry Pi
from gpiozero import Buzzer buzzer = Buzzer(17) buzzer.on() print('Buzzer is on') buzzer.off() print('Buzzer is off')
Attempts:
2 left
💡 Hint
The print statements execute immediately after turning the buzzer on and off.
✗ Incorrect
The code turns the buzzer on, prints 'Buzzer is on', then turns it off and prints 'Buzzer is off'. So the output is two lines in that order.
❓ Predict Output
intermediate2:00remaining
What frequency does TonalBuzzer play?
Given this code snippet using gpiozero's TonalBuzzer, what frequency will the buzzer play?
Raspberry Pi
from gpiozero import TonalBuzzer buzzer = TonalBuzzer(18) buzzer.play('C4') print(buzzer.frequency)
Attempts:
2 left
💡 Hint
C4 is middle C note frequency.
✗ Incorrect
The note 'C4' corresponds to 261.63 Hz, so buzzer.frequency will be 261.63.
🔧 Debug
advanced2:00remaining
Why does this Buzzer code raise an error?
This code snippet raises an error. What is the cause?
Raspberry Pi
from gpiozero import Buzzer buzzer = Buzzer() buzzer.on()
Attempts:
2 left
💡 Hint
Check the Buzzer constructor requirements.
✗ Incorrect
Buzzer requires a GPIO pin number argument. Omitting it causes a TypeError.
❓ Predict Output
advanced2:00remaining
What is the output of this TonalBuzzer sequence?
What will be printed after running this code?
Raspberry Pi
from gpiozero import TonalBuzzer buzzer = TonalBuzzer(18) buzzer.play('C4') print(round(buzzer.frequency, 2)) buzzer.play('E4') print(round(buzzer.frequency, 2)) buzzer.stop() print(buzzer.frequency)
Attempts:
2 left
💡 Hint
Check the frequency attribute after play and stop.
✗ Incorrect
The buzzer plays C4 (261.63 Hz), then E4 (329.63 Hz), then stops which sets frequency to None.
🧠 Conceptual
expert2:00remaining
Which option causes a runtime error when using TonalBuzzer?
Which of the following code snippets will cause a runtime error when executed on a Raspberry Pi with gpiozero TonalBuzzer?
Attempts:
2 left
💡 Hint
Check if 'Z4' is a valid musical note.
✗ Incorrect
'Z4' is not a valid note, so play('Z4') raises a ValueError at runtime.