forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeedTypingTestInPython.py
61 lines (46 loc) · 1.81 KB
/
SpeedTypingTestInPython.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
### Speed Typing Test in python ###
# Imported Library
import time
import threading
# Created Class
class tester:
def __init__(self, paragraph):
self.correctWords = []
self.incorrectWords = {}
self.typedWords = []
self.totalWords = []
self.input = None
self.paragraph = paragraph
self.accuracy = 0
self.time = 0
self.wordPermin = 0
self.run()
#### Defined the Variable ###
def clock(self):
while len(self.typedWords) == 0:
self.time += 1
time.sleep(1)
def run(self):
threading.Thread(target=self.clock).start()
threading.Thread(target=self.testSpeed).start()
def testSpeed(self):
print('\n\n'+self.paragraph+'\n\n')
self.input = str(input('\t\n'+'Type The Word Which You Want To Know the Speed As well as Incorrect \n\n'))
self.totalWords = self.paragraph.split(' ')
self.typedWords = self.input.split(' ')
try:
for i in range(len(self.typedWords)):
if(self.typedWords[i] == self.totalWords[i]):
self.correctWords.append(self.typedWords[i])
else:
self.incorrectWords.update({self.totalWords[i] : self.typedWords[i]})
except Exception as e:
print(e)
self.accuracy = len(self.correctWords)/len(self.typedWords) * 100
self.wordPerMin = len(self.typedWords) / (self.time/60)
print('\n\nResult :--')
print(f'Accuracy: -- {self.accuracy}')
print(f'Word Per Minute :-- {self.wordPerMin}')
print(f'Incorrect Words :-- {self.incorrectWords}')
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.")
### The Code is ended, Thank You ####