-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactionTime.py
114 lines (105 loc) · 4.26 KB
/
reactionTime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Programmer: Ryan Lee
This program is a simple game meant to test reaction speed. Instructions are provided upon running the code.
The program will automatically record the results in a list that can be easily viewed outside of the trials, and uses a threshold time to prevent accidental
early inputs from skewing the resulting data.
I hope any who use this code have fun!
"""
import time
import random
# Introductory text that provides info about how to use this program to the viewer
intro_text = "Hello! This program will test your reaction time.\n\
Before typing, please read the following information carefully: \n \
1. If you wish to quit, please type 'quit' and press enter \n \
2. When the test begins, there will be a pause after the message 'Get Ready!' that lasts \
anywhere from 1-10 seconds, followed by a bunny appearing on screen.\n \
When you see the bunny, press enter as soon as possible \n \
(to see the bunny outside of trials, type 'bunny') \n \
3. Your time will be printed on the screen, and all of your results from this session will be stored in a list.\n \
To view the list, please type 'view' \n \
5. To begin the test, type 'start' \n \
6. Finally, for a list of all available commands, type 'help'"
# A list of commands that can be printed with the right keyword
commands = "Commands: \n To quit: 'quit' \n To start the test: 'start' \n To view previous times: 'view' \n To view the bunny: 'bunny' \n To view the commands: 'help'"
# Just a cute style choice
# Acts as the trigger message for the test
# Large enough to be easily visible to the viewer when printed
bunny = "\
|-----------| \n\
| NOW!!! | \n\
|-----------| \n\
(\__/) || \n\
(•ㅅ•) || \n\
/ づ "
# Will store user input for later
value = ""
# Will track how many times the test has been run
counter = 0
# List to store all previous times
times = []
# Holds the number of seconds to wait before printing the bunny
wait = 0
# Checks time when bunny is printed
start = 0
# Checks time when user reaction is recorded
end = 0
# Amount of time (in seconds) it took to react
speed = 0
# Threshold: If overall time is < threshold, the likelihood of cheating (providing input before bunny appears) is
# high, so the time will be deleted and another trial will run
# Note: Threshold is based on the time it takes for light stimuli to reach the brain
threshold = 0.1
# Error: boolean value used to make sure the number of trials requested is a useable integer
error = True
print(intro_text)
while value != "quit" :
value = input("Command: ").lower()
if value == "help":
print(commands)
elif value == "view":
print(times)
print("Print result into a file?")
value = input("y/n: ").lower()
if value == "y":
target = open("speed.csv", "w")
for x in times:
print(x)
print(x, file = target)
target.close
elif value == "n":
print("Okay!")
elif value == "bunny":
print(bunny)
elif value == "start":
print("How many times would you like to run the test?")
while error:
try:
count = int(input("Number: "))
except ValueError:
print("Error: Please only input integers")
continue
break
x = 0
while x < count:
print("Beginning...\n")
time.sleep(2)
print("GET READY!\n")
wait = random.randint(1, 10)
time.sleep(wait)
print(bunny)
start = time.time()
if input() != None:
end = time.time()
speed = end - start
if speed < threshold:
print("WARNING: Possible cheating detected \n Please do not provide input before bunny appears. \n This trial will be restated.\n")
time.sleep(1)
else:
x += 1
counter += 1
times.append((speed))
print(f"Your time was: {speed} seconds")
print(f"The program has been run {counter} times \n")
# Refresh value to prevent bugs like the above commands running in between trials
value = ""
print(f"{count} trials completed")