-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
typing_speed.py
65 lines (49 loc) · 1.6 KB
/
typing_speed.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
# This code is made by MRayan Asim
from time import time
# calculate the accuracy of the input prompt
def typingErrors(prompt):
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 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 = "Hi, this code is written by MRayan asim, a programmer"
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")