Bird
0
0

What will be the output of this code snippet in a reaction time game?

medium📝 Predict Output Q13 of 15
Raspberry Pi - LED and Button Projects
What will be the output of this code snippet in a reaction time game?
import time
start = time.time()
# LED lights up here
input('Press Enter as fast as you can!')
end = time.time()
print(f'Reaction time: {end - start:.2f} seconds')
ANo output because input() is not called
BReaction time: 0.00 seconds
CSyntaxError due to missing parentheses
DReaction time: time taken between prompt and Enter press
Step-by-Step Solution
Solution:
  1. Step 1: Understand timing with time.time()

    The code records time before and after waiting for user input.
  2. Step 2: Calculate reaction time

    The difference end - start measures how long the user took to press Enter after the prompt.
  3. Final Answer:

    Reaction time: time taken between prompt and Enter press -> Option D
  4. Quick Check:

    Reaction time = end - start after input [OK]
Quick Trick: time.time() difference measures reaction delay [OK]
Common Mistakes:
  • Assuming reaction time is always zero
  • Confusing syntax errors with correct code
  • Thinking input() is not called

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes