File size: 1,135 Bytes
cdec65b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#iport libraries
import time
import random

# Some sentences to test typing speed
sentences = [
    "Python is a great programming language",
    "Artificial Intelligence is the future",
    "Machine learning makes computers intelligent",
    "Typing speed test game is fun to play",
    "Data science is changing the world"
]

# Pick random sentence
sentence = random.choice(sentences)
print("\n💻 Type this sentence as fast as you can:\n")
print("👉", sentence)
print()

# Start typing
input("Press Enter when you are ready to start...\n")
start_time = time.time()
typed = input("Start Typing: \n")
end_time = time.time()

# Calculate speed and accuracy
time_taken = round(end_time - start_time, 2)
words = sentence.split()
typed_words = typed.split()

correct = 0
for i in range(min(len(words), len(typed_words))):
    if words[i] == typed_words[i]:
        correct += 1

accuracy = round((correct / len(words)) * 100, 2)
wpm = round(len(typed_words) / (time_taken / 60))

print("\n⏱️ Time Taken:", time_taken, "seconds")
print("✅ Accuracy:", accuracy, "%")
print("⚡ Your Typing Speed:", wpm, "words per minute (WPM)")