0
0
Raspberry Piprogramming~20 mins

Buzzer and TonalBuzzer in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Buzzer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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')
ARuntimeError: GPIO pin not accessible
BBuzzer is off\nBuzzer is on
CBuzzer is on\nBuzzer is off
DNo output
Attempts:
2 left
💡 Hint
The print statements execute immediately after turning the buzzer on and off.
Predict Output
intermediate
2: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)
A261.63
B440.00
C329.63
DNone
Attempts:
2 left
💡 Hint
C4 is middle C note frequency.
🔧 Debug
advanced
2: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()
AValueError because pin number is negative
BRuntimeError because buzzer is already on
CSyntaxError due to missing colon
DTypeError because pin number is missing when creating Buzzer
Attempts:
2 left
💡 Hint
Check the Buzzer constructor requirements.
Predict Output
advanced
2: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)
A261.63\n329.63\nNone
BSyntaxError
C261.63\n329.63\n0
DNone\nNone\nNone
Attempts:
2 left
💡 Hint
Check the frequency attribute after play and stop.
🧠 Conceptual
expert
2: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?
Abuzzer = TonalBuzzer(18)\nbuzzer.stop()
Bbuzzer = TonalBuzzer(18)\nbuzzer.play('Z4')
Cbuzzer = TonalBuzzer(18)\nbuzzer.play('A4')
Dbuzzer = TonalBuzzer(18)\nprint(buzzer.frequency)
Attempts:
2 left
💡 Hint
Check if 'Z4' is a valid musical note.