Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Browse our collection of 100+ mini-projects organized by category:
- [Black Jack](./Black_Jack_Game) - Card game simulation
- [Russian Roulette](./Russian%20Roulette) - Probability game
- [Slot Machine](./slot-machine) - Casino-style slot game
- [Typing Speed Tester CLI](./Typing-Speed-Tester-CLI) - Terminal-based WPM and accuracy tester game

### Web Development
- [Beautiful JS Clock](./Beautiful%20JS%20Clock) - Animated clock interface
Expand Down
47 changes: 47 additions & 0 deletions Typing-Speed-Tester-CLI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ⌨️ Typing Speed Tester CLI

A terminal-based typing speed tester that measures your WPM and accuracy — no browser, no setup, just Python.

## Features

- Randomly selects a sentence each round
- Measures **WPM** (words per minute) and **accuracy** (per word)
- Color-coded feedback — green for correct words, red for mistyped ones
- Session summary with averages and best score after multiple rounds

## Demo

```
⌨ Typing Speed Tester

Type the sentence below as fast and accurately as you can.

───────────────────────────────────────────────────────
coding is the closest thing we have to a superpower
───────────────────────────────────────────────────────

> coding is the closest thing we have to a superpower

WPM : 72
Accuracy : 100% (9/9 words correct)
Time : 7.48s
```

## Requirements

Python 3.x — no external libraries needed.

## Usage

```bash
python typing_speed_tester.py
```

Type the displayed sentence and press Enter. Type `quit` to end the session.

## How It Works

- Timer starts when you press Enter to begin
- Each word in your input is compared against the original
- WPM is calculated as `(word_count / elapsed_seconds) * 60`
- Accuracy is `correct_words / total_words * 100`
94 changes: 94 additions & 0 deletions Typing-Speed-Tester-CLI/typing-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import time
import random
import sys

SENTENCES = [
"the quick brown fox jumps over the lazy dog",
"coding is the closest thing we have to a superpower",
"practice makes perfect but nobody is perfect so why practice",
"python is a versatile language used in web development and data science",
"open source contributions help developers grow and build their portfolios",
"artificial intelligence is transforming the way humans interact with machines",
"the best way to predict the future is to create it yourself",
"every expert was once a beginner who refused to give up",
"simplicity is the ultimate sophistication in software design",
"debugging is twice as hard as writing the code in the first place",
"the efficiency we have at removing trash has made creating trash more acceptable",
"the only way to do great work is to love what you do",
]

def colored(text, code): return f"\033[{code}m{text}\033[0m"
def green(t): return colored(t, "92")
def red(t): return colored(t, "91")
def cyan(t): return colored(t, "96")
def bold(t): return colored(t, "1")

def compare(original, typed):
result, correct = "", 0
words_o, words_t = original.split(), typed.split()
for i, word in enumerate(words_o):
typed_word = words_t[i] if i < len(words_t) else ""
if typed_word == word:
result += green(word) + " "
correct += 1
else:
result += red(word) + " "
return result.strip(), correct, len(words_o)

def run():
print(bold(cyan("\n⌨ Typing Speed Tester\n")))
print("Type the sentence below as fast and accurately as you can.")
print("Press Enter when done. Type 'quit' to exit.\n")

scores = []
while True:
sentence = random.choice(SENTENCES)
print(bold("─" * 55))
print(f"\n{cyan(sentence)}\n")
print(bold("─" * 55))

try:
input("Press Enter to start...")
print("\033[1A\033[K", end="") # clears the prompt line
start = time.time()
typed = input("> ").strip()
elapsed = time.time() - start
except (KeyboardInterrupt, EOFError):
break

if typed.lower() == "quit":
break

if elapsed < 0.5:
print(red("Too fast — did you actually type that?\n"))
continue

wpm = round((len(sentence.split()) / elapsed) * 60)
result, correct, total = compare(sentence, typed)
accuracy = round((correct / total) * 100)

print(f"\n{result}\n")
print(f" {bold('WPM')} : {green(str(wpm))}")
print(f" {bold('Accuracy')}: {green(str(accuracy) + '%')} ({correct}/{total} words correct)")
print(f" {bold('Time')} : {elapsed:.2f}s\n")

scores.append((wpm, accuracy))

again = input("Try again? (y/n): ").strip().lower()
print()
if again != "y":
break

if scores:
avg_wpm = round(sum(s[0] for s in scores) / len(scores))
avg_acc = round(sum(s[1] for s in scores) / len(scores))
print(bold(cyan(" Session Summary: ")))
print(f" Rounds : {len(scores)}")
print(f" Avg WPM : {green(str(avg_wpm))}")
print(f" Avg Acc : {green(str(avg_acc) + '%')}")
best = max(scores, key=lambda s: s[0])
print(f" Best WPM : {green(str(best[0]))} (at {best[1]}% accuracy)")
print("\nGood session. See ya! \n")

if __name__ == "__main__":
run()
Loading