0
0
Raspberry Piprogramming~10 mins

Reaction time game in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the module needed to measure time.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Atime
Brandom
Cgpiozero
Dsys
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong module like random or gpiozero instead of time.
2fill in blank
medium

Complete the code to wait for a random time between 1 and 3 seconds before starting the reaction timer.

Raspberry Pi
import random
import time

wait_time = random.[1](1, 3)
time.sleep(wait_time)
Drag options to blanks, or click blank then click option'
Achoice
Buniform
Crandom
Drandint
Attempts:
3 left
💡 Hint
Common Mistakes
Using random.choice which picks from a list, not a range.
Using random.uniform which picks a float, not an integer.
3fill in blank
hard

Fix the error in the code that measures the reaction time by capturing start and end times.

Raspberry Pi
start = time.[1]()
# wait for user input here
end = time.perf_counter()
reaction_time = end - start
Drag options to blanks, or click blank then click option'
Asleep
Btime
Cperf_counter
Dprocess_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using time.sleep which pauses the program.
Using time.time which is less precise for short intervals.
4fill in blank
hard

Fill both blanks to create a dictionary that stores reaction times for each player if their time is less than 2 seconds.

Raspberry Pi
reaction_times = {player: [1] for player, [2] in results.items() if [1] < 2}
Drag options to blanks, or click blank then click option'
Atime
Bscore
Creaction
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for player and time.
Using undefined variable names.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores uppercase player names as keys and their scores if scores are above 0.

Raspberry Pi
high_scores = { [1]: [2] for [3], [2] in scores.items() if [2] > 0}
Drag options to blanks, or click blank then click option'
Aplayer.upper()
Bscore
Cplayer
Dpoints
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variable names or using undefined variables.
Not using the upper() method for keys.