Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Typing Speed Test Program #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions TypingSpeedTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from time import time


def checkText(text, ans):
errs = []
small_err = 0

if len(text) > len(ans):
errs += [i for i in range(len(ans), len(text))]
text = text[: len(ans)]

elif len(text) < len(ans):
small_err = len(ans) - len(text)

for i in range(len(text)):
if text[i] != ans[i]:
errs.append(i)

return errs, small_err


def calc_speed(text, time_taken):
words = len(text) / 5
return round(words / time_taken * 60, 1)


def_ques = "The quick brown fox jumps over the lazy dog."

ques = input(
"Enter the text you will be typing during the test (leave empty to select default text)\n : "
)

if not ques:
ques = def_ques

print(f"Type this :- '{ques}'")
input("Press ENTER whe you are ready")

start_time = time()
text = input()
end_time = time()

errors, small_len_err = checkText(text, ques)

print("\nYour Report:\n")

time_taken = round(end_time - start_time, 3)

print(f"Number of words: {len(text) / 5} (calculated as number of characters / 5)")
print(f"Time Taken: {time_taken}s")
print(f"Speed: {calc_speed(text, time_taken)}wpm")
print(f"Number of mistakes: {len(errors) + small_len_err}")

if len(errors) + small_len_err > 0:
print("Your mistakes are highlighted by brakets around them")
for i in range(len(text)):
if i in errors:
print(f"[{text[i]}]", end="")
else:
print(text[i], end="")
if small_len_err:
print(f" ({small_len_err} characters missing)")