Make your own typing speed calculator using python.
Welcome to typing speed calculator
This is make your own typing speed calculator using python. You import random and numpy.
from time import time
import random as r
import numpy as np
def levenshtein_distance(s1, s2):
if len(s1) < len(s2):
return levenshtein_distance(s2, s1)
if len(s2) == 0:
return len(s1)
previous_row = range(len(s2) + 1)
for i, c1 in enumerate(s1):
current_row = [i + 1]
for j, c2 in enumerate(s2):
insertions = previous_row[j + 1] + 1
deletions = current_row[j] + 1
substitutions = previous_row[j] + (c1 != c2)
current_row.append(min(insertions, deletions, substitutions))
previous_row = current_row
return previous_row[-1]
def mistake(paragraph, user):
error = 0
total_chars = len(paragraph)
for i in range(min(len(paragraph), len(user))):
if paragraph[i] != user[i]:
error += 1
return (error / total_chars) * 100 if total_chars > 0 else 0
def speed_time(time_start, time_end, user_input):
time_delay = time_end - time_start
time_R = round(time_delay, 2)
speed = len(user_input) / time_R
return round(speed), time_R
def accuracy(paragraph, user):
total_chars = len(paragraph)
correct_chars = sum(1 for p, u in zip(paragraph, user) if p == u)
return (correct_chars / total_chars) * 100 if total_chars > 0 else 0
test = ["You will find hundreds of training videos on our YouTube channel to help explore a wide range of IT topics.",
"what you are know doing.",
"this is a new typing speed calculator."]
test1 = r.choice(test)
print(" * * * * * Typing speed * * * * * ")
print(test1)
print()
time_1 = time()
test_input = input("Enter: ")
time_2 = time()
speed, time_taken = speed_time(time_1, time_2, test_input)
error_percent = mistake(test1, test_input)
accuracy_percent = accuracy(test1, test_input)
print("Speed:", speed, "wps.")
print("Time taken:", time_taken, "seconds.")
print("Error:", "{:.2f}%".format(error_percent))
print("Accuracy:", "{:.2f}%".format(accuracy_percent))
Comments