-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtyping_test.py
More file actions
47 lines (41 loc) · 1.8 KB
/
Copy pathtyping_test.py
File metadata and controls
47 lines (41 loc) · 1.8 KB
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
import random2
from __init__ import get_configuration
from sys import platform
class TypingTest:
def __init__(self):
self.random_no_of_words, self.start_method, self.difficulty = get_configuration()
def get_random_words(self):
if self.difficulty == 'easy':
with open('easy_difficulty.txt', 'r') as f:
words_list = f.read().split(',')
elif self.difficulty == 'difficult':
with open('dictionary.txt', 'r') as f:
words_list = f.read().split(',')
else:
if platform == 'linux':
file = 'typing_practice.py'
python_interpreter_call_command = 'python3'
elif platform == 'win32':
file = 'install_tt.py'
python_interpreter_call_command = 'py'
else:
exit()
print(f'There was some mistake in the difficulty in configuration file. Use "{python_interpreter_call_command} {file} configure" to fix this issue')
print('The difficulty options are: easy & difficult. Enter one of these when prompted.')
exit()
random_words = []
for x in range(0 , self.random_no_of_words):
random_word = random2.choice(words_list)
random_words.append(random_word)
return random_words
def calculate_wpm(self, words, time_taken):
number_of_characters = 0
for word in words:
number_of_characters += len(word)
number_of_characters = number_of_characters + len(words) - 1
average_number_of_words = number_of_characters / 5
wpm = average_number_of_words / (time_taken / 60), number_of_characters
return wpm
if __name__ == '__main__':
tt = TypingTest()
print(tt.get_random_words(25))