forked from Kushal-Pareek/CodeRed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyping_test.py
60 lines (45 loc) · 1.42 KB
/
typing_test.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
# A simple python typing test
from time import time
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
def typingSpeed(iprompt, stime, etime):
global time
global iwords
iwords = iprompt.split()
twords = len(iwords)
speed = twords*60 / time
return speed
def timeElapsed(stime, etime):
time = etime - stime
return time
if __name__ == '__main__':
prompt = "Hi, i would like to know my typing speed."
print("Type the following:- '", prompt, "'")
input("Press ENTER when ready...")
stime = time()
iprompt = input()
etime = time()
time = round(timeElapsed(stime, etime), 2)
speed = typingSpeed(iprompt, stime, etime)
errors = typingErrors(prompt)
print("Total Time elapsed : ", time, "s")
print("Your Average Typing Speed was : ", speed, "words / minute")
print("With a total of : ", errors, "errors")
input("")