Sharpen your typing skills with this fun and fully terminal-based Python project!
📌 What We'll Build:
A simple terminal-based typing game that:
Generates a random sentence.
Tracks your typing speed in Words Per Minute (WPM).
Shows accuracy percentage.
Highlights correct and incorrect characters as you type.
And all that using Python + the powerful rich
and time
modules.
🧰 Requirements
Install rich
for colorful terminal output:
pip install rich
🧠 The Logic
Pick a random sentence from a list.
Start a timer when typing begins.
Compare typed characters to the original.
On Enter, calculate time taken, WPM, and accuracy.
💻 Full Python Code:
import random
import time
from rich.console import Console
from rich.prompt import Prompt
from rich.text import Text
console = Console()
sentences = [
"The quick brown fox jumps over the lazy dog.",
"Python is an amazing programming language.",
"Typing speed improves with daily practice.",
"Focus on accuracy before increasing speed.",
"Challenge yourself to be faster and better."
]
def calculate_wpm(start, end, typed_text):
words = len(typed_text.split())
elapsed_minutes = (end - start) / 60
return round(words / elapsed_minutes) if elapsed_minutes > 0 else 0
def calculate_accuracy(original, typed):
correct = sum(o == t for o, t in zip(original, typed))
total = len(original)
return round((correct / total) * 100) if total > 0 else 0
def highlight_text(original, typed):
result = Text()
for i, char in enumerate(original):
if i < len(typed):
if typed[i] == char:
result.append(char, style="bold green")
else:
result.append(char, style="bold red")
else:
result.append(char, style="dim")
return result
def main():
console.clear()
console.rule("[bold blue]Typing Speed Test")
sentence = random.choice(sentences)
console.print("\nType the following sentence:\n", style="bold yellow")
console.print(sentence + "\n", style="italic cyan")
input("Press Enter when ready to start...")
console.clear()
console.print(sentence + "\n", style="italic cyan")
start_time = time.time()
typed = Prompt.ask("\nStart typing")
end_time = time.time()
wpm = calculate_wpm(start_time, end_time, typed)
accuracy = calculate_accuracy(sentence, typed)
console.print("\n[bold underline]Results[/bold underline]")
console.print(f"WPM: [bold green]{wpm}[/bold green]")
console.print(f"Accuracy: [bold magenta]{accuracy}%[/bold magenta]")
console.print("\n[bold]Comparison:[/bold]")
console.print(highlight_text(sentence, typed))
if __name__ == "__main__":
main()
🎯 Sample Output:
💡 What You Can Add Next
Time limit countdown (e.g. 30 seconds).
Typing leaderboard with file storage.
GUI version with tkinter
or pygame
.
Option to choose difficulty level.
🚀 Final Thoughts
This project is perfect for:
Practicing terminal UI skills.
Working with timers, string processing, and input handling.
Sharpening your Python logic skills while building something fun!.
If you enjoyed this, don't forget to ❤️ and share!.
Top comments (1)
🧠 By the way, my WPM is just 47 and max is like 57😅 — definitely room for improvement!
What’s your WPM? Try it out and drop your score in the comments. Let’s see who’s got the fastest fingers! ⌨️🔥