forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyping_speed_test.py
59 lines (49 loc) · 1.67 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
from time import time
#definig function errors which will calculate the accuracy
global correct
def Errors(prompt):
words = prompt.split()
errors = 0
#splitting thw words to get error
for i in range(len(correct)):
if i in (0, len(correct)-1):
if correct[i] == words[i]:
continue
else:
errors +=1
else:
if correct[i] == words[i]:
if (correct[i+1] == words[i+1]) & (correct[i-1] == words[i-1]):
continue
else:
errors += 1
else:
errors += 1
return errors
#Speed function to calculate number of words written per unit time(minute)
def Speed(iprompt, starttime, endtime):
global time
global correct
correct = iprompt.split()
twords = len(correct)
speed = twords / time
return speed
#Time function to calculate amount of time taken by user
def timeElapsed(startime, endtime):
time = endtime - starttime
return time
if __name__ == '__main__':
prompt = "Hi, my name is Neel Shah, I am a python lover."
print("Type this:- '", prompt, "'")
input("press ENTER when you are ready!")
#Gathering all the data
starttime = time()
iprompt = input()
endtime = time()
time = round(timeElapsed(starttime, endtime), 2)
speed = Speed(iprompt, starttime, endtime)
errors = Errors(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")