Hello python programmers, This is AK in this blog we’re going to learn about how to create your
own typing speed tester program using python. Before starting this program you must have a
strong basics knowledge of python programming. So this program is a super simple one and
it produces more accurate results.
For this program, you don’t need to install any python packages. I'm using the built-in packages
to create this program. So don’t worry about the package installations.
Step 1 :
For checking the typing speed of yours, you’ve to type some words to generate your results.
For that process create a variable called a string and in this variable, you’ve to type some sentences.
import time
String='subscribe to Akpython'
Why we are creating this variable means. For checking your typing speed you need to type some
sentences. According to that typing performances, the results are generated. So this our process.
And you need to type this sentence in the output to check your typing accuracy, wpm and time taken
Step 2:
Next, create a variable called word count and in this variable, you need to print the length of the
sentence that you’re going to type.
wordcount=len(String.split())
print(String)
Previously we declared a string as a sentence For counting each word on the sentence you
need to split the variable string. In python, There is one useful method is split(). Using this split we
can easily split the string into list form. Using the length method we can easily find out the length of
each string after splitting the sentence.
Step 3:
while True:
t0=time.time()
inputtext=str(input('Enter the Sentence:'))
t1=time.time()
So next step we need to create a loop and in this loop, we’re going to calculate the time taken to
type the sentence. After that, you need to create an input text when you run this script you’re going to
type the entire sentence in this variable. When you’re typing the sentence this program analysis your
all typing speed, accuracy, words per minute to type the sentence.
These are the parameters we’re going to calculate under this while loop, First, we’re going to calculate
the typing speed, For calculating the typing speed you need to find the difference between starting time
& ending time of your typing.
Create a variable called t0 and pass the object time.time() and So this variable used to record the
starting time and next you’ve to create another variable called t1. Consider this variable as ending time.
When subtracting these two-variable timings we get the time taken to type the entire word
Step 4:
Next, create a variable called accuracy we are going to find out the accuracy of our typing.
Suppose when you are missing some words in the actual sentences then your accuracy rank
will get low.
accuracy=len(set(inputtext.split())&set(String.split()))
accuracy=accuracy/wordcount
So in this variable, you need to use the set method to find out the uniqueness in both sentences.
So we’re calling the set of input text that we’re going to type and also we’re calling another set that
is a set of the actual string.
If you miss any words in the input text variable your length of the word is going to decrease.
When your length of the sentence that decreases your accuracy also decreases. So this is a concept
I think you will understand this step.
And in this accuracy variable you need to make the formula as accuracy divided by word count
this is the formula to find out the accuracy of your typing
Step 5:
timetaken=t1-t0
wpm=wordcount/timetaken
print("WPM",wpm,"Accuracy",accuracy,"Timetaken",timetaken)
So in the case of words per minute, we’re having some formula that is word_count is divided by the
time taken.
So this formula is used to produces the wpm result of your typing.
And finally, print the statement, and let’s run this program
No comments:
Post a Comment