-
Notifications
You must be signed in to change notification settings - Fork 1
/
Typing_Speed_Test.py
75 lines (56 loc) · 1.98 KB
/
Typing_Speed_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 = "Hi my name is abdo_elsharef Iam a python devlober and python is my lovly languashe."
print(f"Type this:- ' { prompt } ' ")
# listening to input ENTER
input("press ENTER to start typing! :".title())
# 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")
# Type this:- ' Hi my name is abdo_elsharef Iam a python devlober and python is my lovly languashe. '
# Press Enter To Start Typing! :
# hi my name is abdo elsharef aam apython devlober and python is my lovly languahse
# Total Time elapsed : 31.05 s
# Your Average Typing Speed was : 0.4830917874396135 words / minute
# With a total of : 10 errors