Reaction Speed

The Task

Write a program to test your reaction speed.  The program must:

  • wait a short, random period of time,
  • then alert you in someway – this could be via text or in a GUI.
  • you will press a key as quickly as you can;
  • the program will measure the difference in time between the flash and your click and display the results for the user to see;
  • you should be able to practice over and over until you decide to quit.

Hint

Measuring elapsed time in python is reasonably simple with the time library. Read the comments carefully in the following example to understand how it works.

pythonTimeDiff

In the previous example we used time.sleep() to hold the program for a set amount of time.  If you wanted that amount of time to vary then it would make sense to replace the 2 with a random number.  The input command can also be used to pause a program until the user tells it to continue.

pythonTimeDiff2

 

Credit Blundell@MonktonCoombe

About CDB 362 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.