-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (50 loc) · 1.83 KB
/
main.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
from time import time
# calculate the accuracy of input prompt
def typingErrors(prompt):
global iwords
words = prompt.split()
errors = 0
for i in range(len(iwords)):
if i in (0, len(iwords)-1):
if iwords[i] == words[i]:
continue
else:
errors +=1
else:
if iwords[i] == words[i]:
if (iwords[i+1] == words[i+1]) & (iwords[i-1] == words[i-1]):
continue
else:
errors += 1
else:
errors += 1
return errors
# calculate the speed in words per minute
def typingSpeed(iprompt, stime, etime):
global time
global iwords
iwords = iprompt.split()
twords = len(iwords)
speed = twords / time
return speed
# calculate total time elapsed
def timeElapsed(stime, etime):
time = etime - stime
return time
if __name__ == '__main__':
prompt = "Although most people consider piranhas to be quite dangerous, they are, for the most part, entirely harmless. Piranhas rarely feed on large animals; they eat smaller fish and aquatic plants. When confronted with humans, piranhas’ first instinct is to flee, not attack. Their fear of humans makes sense."
print("Type this:- '", prompt, "'")
# listening to input ENTER
input("press ENTER when you are ready!")
# recording time for input
stime = time()
iprompt = input()
etime = time()
# gather all the information returned from functions
time = round(timeElapsed(stime, etime), 2)
speed = typingSpeed(iprompt, stime, etime)
errors = typingErrors(prompt)
# printing all the required data
print("Total Time elapsed : ", time, "s")
print("Your Average Typing Speed was : ", speed, "words / minute")
print("With a total of : ", errors, "errors")