1
+ ### Speed Typing Test in python ###
2
+
3
+ # Imported Library
4
+
5
+ import time
6
+ import threading
7
+
8
+ # Created Class
9
+
10
+ class tester :
11
+ def __init__ (self , paragraph ):
12
+ self .correctWords = []
13
+ self .incorrectWords = {}
14
+ self .typedWords = []
15
+ self .totalWords = []
16
+ self .input = None
17
+ self .paragraph = paragraph
18
+ self .accuracy = 0
19
+ self .time = 0
20
+ self .wordPermin = 0
21
+ self .run ()
22
+
23
+ #### Defined the Variable ###
24
+
25
+ def clock (self ):
26
+ while len (self .typedWords ) == 0 :
27
+ self .time += 1
28
+ time .sleep (1 )
29
+
30
+ def run (self ):
31
+ threading .Thread (target = self .clock ).start ()
32
+ threading .Thread (target = self .testSpeed ).start ()
33
+
34
+ def testSpeed (self ):
35
+ print ('\n \n ' + self .paragraph + '\n \n ' )
36
+ self .input = str (input ('\t \n ' + 'Type The Word Which You Want To Know the Speed As well as Incorrect \n \n ' ))
37
+ self .totalWords = self .paragraph .split (' ' )
38
+ self .typedWords = self .input .split (' ' )
39
+
40
+ try :
41
+ for i in range (len (self .typedWords )):
42
+ if (self .typedWords [i ] == self .totalWords [i ]):
43
+ self .correctWords .append (self .typedWords [i ])
44
+ else :
45
+ self .incorrectWords .update ({self .totalWords [i ] : self .typedWords [i ]})
46
+
47
+ except Exception as e :
48
+ print (e )
49
+
50
+
51
+ self .accuracy = len (self .correctWords )/ len (self .typedWords ) * 100
52
+ self .wordPerMin = len (self .typedWords ) / (self .time / 60 )
53
+
54
+ print ('\n \n Result :--' )
55
+ print (f'Accuracy: -- { self .accuracy } ' )
56
+ print (f'Word Per Minute :-- { self .wordPerMin } ' )
57
+ print (f'Incorrect Words :-- { self .incorrectWords } ' )
58
+
59
+ Mytester = tester ("You know you're a programmer when you spend a day to find the problem, and then fix it with one line of code." )
60
+
61
+ ### The Code is ended, Thank You ####
0 commit comments