-
Notifications
You must be signed in to change notification settings - Fork 0
/
testspeedtyping.py
36 lines (28 loc) · 1.17 KB
/
testspeedtyping.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
import random
import time
def speed_typing_test():
sentences = [
"The quick brown fox jumps over the lazy dog.",
"Programming is fun and rewarding.",
"Practice makes perfect.",
"Python is a versatile programming language.",
"Learning to code opens up many opportunities."
]
sentence = random.choice(sentences)
print("Type the following sentence as fast as you can:")
print(sentence)
input("Press Enter to start...")
start_time = time.time()
typed_sentence = input("Type the sentence: ")
end_time = time.time()
elapsed_time = end_time - start_time
words = typed_sentence.split()
correct_words = sum(1 for typed_word, original_word in zip(words, sentence.split()) if typed_word == original_word)
accuracy = (correct_words / len(sentence.split())) * 100
words_per_minute = (len(words) / elapsed_time) * 60
print("\nTyping test result:")
print(f"Time taken: {elapsed_time:.2f} seconds")
print(f"Accuracy: {accuracy:.2f}%")
print(f"Words per minute: {words_per_minute:.2f} WPM")
if __name__ == "__main__":
speed_typing_test()