Typing speed tester
import time
import random
sentences = [
"The quick brown fox jumps over the lazy dog.",
"Typing fast is a valuable skill in today's world.",
"Practice makes perfect when it comes to typing.",
"Python is a versatile programming language.",
"Always double-check your code for errors."
]
def typing_test():
sentence = random.choice(sentences)
print("\nType the following sentence as quickly and accurately as you can:")
print("\n➡️ ", sentence)
input("Press Enter when you're ready...")
start_time = time.time()
typed = input("\nStart typing:\n")
end_time = time.time()
time_taken = end_time - start_time
time_in_minutes = time_taken / 60
words = len(sentence.split())
wpm = round(words / time_in_minutes)
# Accuracy calculation
correct_chars = sum(1 for i, c in enumerate(typed) if i < len(sentence) and c == sentence[i])
accuracy = round((correct_chars / len(sentence)) * 100, 2)
print(f"\n⏱️ Time taken: {round(time_taken, 2)} seconds")
print(f"💨 Typing Speed: {wpm} words per minute (WPM)")
print(f"🎯 Accuracy: {accuracy}%")
typing_test()
Code output
Type the following sentence as quickly and accurately as you can:
➡️ Practice makes perfect when it comes to typing.
Press Enter when you're ready...practice makes perfect when it comes to typing
Start typing:
⏱️ Time taken: 1.25 seconds
💨 Typing Speed: 382 words per minute (WPM)
🎯 Accuracy: 0.0%