-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedtest.py
78 lines (63 loc) · 1.98 KB
/
speedtest.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
76
import random
import time
import sys
from threading import Timer
def speedCalculation(sen,initial,final):
words=sen.count(" ")+1
timediff=final-initial
return (words/timediff)
def accuracyCalculation(sen,written):
if(len(sen)==len(written)):
count=0
for i in range(0,len(sen)):
if(sen[i]==written[i]):
count=count+1
return (count/len(sen))
elif(len(sen)>len(written)):
print("You haven't entered the complete text")
count=0
minlength=min(len(sen),len(written))
for i in range(0,minlength):
if(sen[i]==written[i]):
count=count+1
return (count/len(sen))
elif(len(sen)<len(written)):
print("You have entered the incorrect text")
def collectSentence():
sentenceslist=[]
with open ('sentences.txt', 'rt') as myfile:
for myline in myfile:
sentenceslist.append(myline.rstrip())
#print(myline)
#print(sentenceslist)
return sentenceslist
def playGame():
sentenceslist=collectSentence()
sentenceindex=random.randrange(0,len(sentenceslist),2)
sen=sentenceslist[sentenceindex]
print(sen)
starttime=time.time()
st=input()
endtime=time.time()
#print(starttime,endtime)
if(round(accuracyCalculation(sen,st)>=0.9)):
print("You have good typing skills")
print("Your accuracy is "+str(round(accuracyCalculation(sen,st)*100,2)))
print(str(round(speedCalculation(sen,starttime,endtime)*60,2))+" words/minute")
while(1):
print("Test your typing skills here")
print("Choose your option")
print("1.Start the test")
print("2.Exit")
#print("The system closes automatically if you choose nothing")
n=(input())
if(int(n)<0 and int(n)>2):
print("Invalid Option")
sys.exit()
elif(n=='1'):
playGame()
elif(n=='2'):
sys.exit()
else:
print("You selected an invalid option")
sys.exit()