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.
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.
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.
IMAGE CREDIT: BiziRacing