-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (38 loc) · 1.77 KB
/
main.py
File metadata and controls
43 lines (38 loc) · 1.77 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
import time
import random
sentences = [
"The quick brown fox jumps over the lazy dog.",
"A journey of a thousand miles begins with a single step.",
"This is the way for us to reference the object of a class."
]
def accuracy(user_input, test_sentence):
correct_chars = sum(1 for a, b in zip(user_input, test_sentence) if a == b)
accuracy = (correct_chars / len(test_sentence)) * 100 if test_sentence else 0
return accuracy
def typing_test():
test_sentence = random.choice(sentences)
print("Type the following sentence as fast as you can:")
print(f"\n{test_sentence}")
input("Press Enter when you're ready...")
start_time = time.time() #Measure the start time, returns time in seconds.
user_input = input("\nStart typing : \n")
end_time = time.time()
time_taken = end_time - start_time
time_taken_in_minutes = time_taken / 60
word_count = len(test_sentence.split(" "))
if user_input == test_sentence:
print("\nResults : ")
print(f"Correct! Time taken: {time_taken:.2f} seconds.")
print(f"Time taken in minutes : {time_taken_in_minutes:.2f} minutes.")
print(f"Words typed : {word_count}")
print(f"Typing speed: {word_count / (time_taken / 60):.2f} words per minute\n")
print(f"Accuracy: {accuracy(user_input, test_sentence):.2f}%")
else:
print("\nIncorrect input.\nTry again!")
print(f"\nYour input : {user_input}")
print(f"Expected input : {test_sentence}")
print(f"Time taken in minutes : {time_taken_in_minutes:.2f} minutes.")
print(f"Words typed : {word_count}")
print(f"Typing speed: {word_count / (time_taken / 60):.2f} words per minute\n")
print(f"Accuracy: {accuracy(user_input, test_sentence):.2f}%")
typing_test()