Python Programming: Typing Speed

LoganTheDudeRox
3 min readApr 24, 2021
Photo by Sergey Zolkin on Unsplash

Typing is a major thing in work, and school nowadays. So why not try to test out your speed? By using this program, you might learn to type faster and faster, and even learn some Python on the way! This article is all about a Python typing speed test, and the steps are right here!

The Imports (Step 1):

For this program, we are going to use Python’s random, and time modules. These both play a major point in this!

import random
import time

The random module can be used for random strings, and the time module can be used to track time!

Word List and Random Words (Step 2):

Now that we have all of the imports, we are going to need the random words and the original list of words.

Unfortunately, I cannot fit all of the words in here, so the first list your going to make is available with: https://pastebin.com/iiU6AH51!

word1 = random.choice(words)
word2 = random.choice(words)
word3 = random.choice(words)
word4 = random.choice(words)
word5 = random.choice(words)
word6 = random.choice(words)
word7 = random.choice(words)
word8 = random.choice(words)
word9 = random.choice(words)
word10 = random.choice(words)
word11 = random.choice(words)
word12 = random.choice(words)

This code uses the list that we created (in the PasteBin above) to choose 12 random words from it. These words are all strings, which can be combined to make a single string

Combining the Strings (Step 3):

This step is rather simple, as you are merging the strings together.

space = " "final_words = word1 + space + word2 + space + word3 + space + word4 + space + word5 + space + word6 + space + word7 + space + word8 + space + word9 + space + word10 + space + word11 + space + word12

This code defines space as a literal space, and then combines the words as final_wordsso we can use them all together as a string!

Tracking the Time (Step 4):

Now that we have all of the needed variables that will not change, we will now need to track the words that are being typed!

print("You will have to type:")
print(final_words)
start = time.time()
sentence = input("Type it now!\n")
end = time.time()

This code tells you the sentence to type, and uses the start and end variable to track the time that we started, and ended at. \n simply means newline, which does what it says, and creates a line-space.

Checking the Sentence (Step 5):

We have now completed asking for the sentence, but what if someone typed in something random… or just pressed enter? There would be no way to tell. With the following code, you’ll be able to do that!

if sentence == final_words:
final_time = end - start
string_time = str(final_time)
print(f"Your time is {string_time} seconds!")
if sentence != final_words:
print("Sadly, you failed! :(")

This code uses an if statement to check whether the sentence is the correct list of words. If it is, it would say your time, and that you won. If you do not win, than it would say you failed.

Running Your Code (Step 6):

Great job! You have finished all of the necessary code required to complete this project! There are 3 basic methods for running the code, and I will be telling you them all!

Method 1: Repl.it

If you are using repl.it to code your program, simply press the button on the top that looks like a play button to run your code! Then type in the black box in response to everything your being asked!

Method 2: Original Python IDE

If you are using the normal Python IDE, the ones that comes when you are downloading Python, you simply will press F5 on your keyboard, or click on “Run” then “Run Module.” This will pop open a new window to use your code!

Method 3: Notepad or any Programming IDE

You would simply open the file directory that your Python file is in, and in that directory open command prompt. In command prompt, you will type py <filename>.py, and you can replace the first py with what you have Python installed as. It could be python, python3, py3, and a few other things!

Thank you for reading this, and hopefully you learned something new! The full code to this in a single file is at this GitHub repository:

https://github.com/LoganLikesToCode/Medium-Articles/blob/main/medium5.py

--

--

LoganTheDudeRox

Hey, I'm a Python Programmer and I love making Discord bots and teaching people!