DEV Community

Cover image for 🧠 Build a Terminal Typing Speed Tester in Python (With WPM & Accuracy Tracking) 🚀
Nishkarsh Pandey
Nishkarsh Pandey

Posted on

4 2 2 2 2

🧠 Build a Terminal Typing Speed Tester in Python (With WPM & Accuracy Tracking) 🚀

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

Enter fullscreen mode Exit fullscreen mode

🧠 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()

Enter fullscreen mode Exit fullscreen mode

🎯 Sample Output:

Output1

💡 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!.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
nish2005karsh profile image
Nishkarsh Pandey

🧠 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! ⌨️🔥

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay