0
0
Raspberry Piprogramming~20 mins

Reaction time game in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Reaction Time Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this reaction time measurement snippet?
Consider this Python code snippet for a reaction time game on Raspberry Pi. What will it print after the user presses Enter?
Raspberry Pi
import time
start = time.time()
input('Press Enter as fast as you can!')
end = time.time()
print(f'Reaction time: {end - start:.3f} seconds')
AReaction time: 1.234 seconds
BReaction time: 0.123 seconds
CReaction time: 0.000 seconds
DSyntaxError
Attempts:
2 left
💡 Hint
The printed time is the difference between when the prompt appears and when Enter is pressed.
🧠 Conceptual
intermediate
1:00remaining
Which Raspberry Pi component is best for detecting a physical button press in a reaction time game?
You want to measure reaction time using a physical button connected to your Raspberry Pi. Which component should you use to detect the button press?
ASPI communication bus
BI2C communication bus
CGPIO pin configured as input with pull-up resistor
DPWM output pin
Attempts:
2 left
💡 Hint
Think about how to read a simple on/off signal from a button.
🔧 Debug
advanced
2:00remaining
Why does this reaction time game code never detect the button press?
This code is supposed to detect a button press on GPIO pin 17 and print reaction time, but it never prints anything. What is the problem?
Raspberry Pi
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)

start = time.time()
while True:
    if GPIO.input(17) == GPIO.HIGH:
        end = time.time()
        print(f'Reaction time: {end - start:.3f} seconds')
        break
AThe loop needs a sleep() call to detect input.
BGPIO.setup should use GPIO.OUT for input pins.
Ctime.time() returns a string, causing a TypeError.
DThe button is wired to pull the pin LOW when pressed, so checking for HIGH never triggers.
Attempts:
2 left
💡 Hint
Check how the button wiring affects the signal level when pressed.
📝 Syntax
advanced
1:30remaining
Which option fixes the syntax error in this Raspberry Pi reaction time code?
This code snippet has a syntax error. Choose the corrected version.
Raspberry Pi
import time
start = time.time()
input('Press Enter')
end = time.time()
print(f'Reaction time: {end - start:.3f seconds')
Aprint(f'Reaction time: {end - start:.3f} seconds')
Bprint(f'Reaction time: {end - start:.3f seconds}')
Cprint('Reaction time: {end - start:.3f} seconds')
D)'}sdnoces f3.:trats - dne{ :emit noitcaeR'f(tnirp
Attempts:
2 left
💡 Hint
Check the placement of the closing brace and parentheses in the f-string.
🚀 Application
expert
3:00remaining
How to implement a non-blocking reaction time game loop on Raspberry Pi?
You want to create a reaction time game that waits a random time, then lights an LED and measures how fast the user presses a button. The program should not freeze while waiting. Which approach is best?
AUse input() to wait for the button press after lighting the LED.
BUse a loop that checks time.time() and GPIO input repeatedly with a small sleep delay.
CUse time.sleep(random_delay) then input() to wait for button press.
DUse a blocking infinite loop without any delay or input.
Attempts:
2 left
💡 Hint
Think about how to keep the program responsive while waiting.