-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeTest.py
More file actions
71 lines (58 loc) · 2.21 KB
/
TypeTest.py
File metadata and controls
71 lines (58 loc) · 2.21 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import time
import random
word_categories = {
"nouns": [
"cat", "dog", "book", "computer", "house", "tree", "cloud", "rain", "sun", "moon",
"ocean", "mountain", "river", "forest", "city", "country", "animal", "bird", "insect", "food"
],
"verbs": [
"walks", "runs", "reads", "writes", "plays", "sleeps", "eats", "drinks", "talks", "sings",
"jumps", "flies", "swims", "crawls", "thinks", "feels", "loves", "hates", "dreams", "wishes"
],
"adjectives": [
"big", "small", "red", "blue", "green", "yellow", "happy", "sad", "angry", "funny",
"tall", "short", "wide", "narrow", "deep", "shallow", "hot", "cold", "soft", "hard"
],
"adverbs": [
"quickly", "slowly", "loudly", "softly", "carefully", "happily", "sadly", "angrily", "funnily",
"very", "really", "quite", "almost", "always", "never", "sometimes", "everywhere", "nowhere"
],
"prepositions": [
"in", "on", "at", "to", "from", "by", "with", "about", "as", "like"
],
"conjunctions": [
"and", "but", "or", "because", "so", "if", "then", "although", "while", "until"
]
}
def random_sentence(min_words=18, max_words=22):
num_words = random.randint(min_words, max_words)
sentence_words = []
for _ in range(num_words):
category = random.choice(list(word_categories.keys()))
random_word = random.choice(word_categories[category])
sentence_words.append(random_word)
sentence = " ".join(sentence_words)
sentence = sentence.capitalize() + '.'
return sentence
def main():
loop = True
while loop :
Sentence = random_sentence()
Words = len(Sentence.split())
print(Sentence)
tint =time.time()
inputtxt = str(input("Enter the Sentence: "))
tend=time.time()
acc = len(set(inputtxt.split())&set(Sentence.split()))
wordsin = len(inputtxt.split())
accuracy= acc/Words
AccPercen= int(accuracy * 100)
timetaken = tend - tint
raw = int(wordsin/timetaken *100)
wpm = int(raw * accuracy)
print("WPM:",wpm,"Accuracy:",AccPercen,"% ""Raw WPM:",raw)
again = input("Again? (y/n): ")
loop = again.lower() == 'y'
print("Exiting...")
if __name__ == '__main__':
main()