Typing Speed Test Python Script

This Python script challenges your typing skills by randomly selecting one of ten unique sentences and measuring your typing speed in words per minute.

Click to view script…
#!/usr/bin/env python3
import time
import random

def typing_speed_test():
    # List of 10 extremely unique sentences for the user to type
    sentences = [
        "The iridescent butterfly fluttered past the ancient clock tower as whispers of the past filled the air.",
        "Under a kaleidoscope sky, the lonely wanderer discovered a secret garden blooming with surreal neon flowers.",
        "Amidst the cosmic silence, a forgotten melody echoed through the labyrinth of interstellar dreams.",
        "In the midst of the bustling city, a solitary violinist played tunes that painted the sunrise in shades of hope.",
        "A cascade of luminous raindrops transformed the mundane street into a magical canvas of vibrant reflections.",
        "The mischievous fox leaped over a neon moon as the forest whispered untold legends in the darkness.",
        "Beneath the ancient cedar, time melted like caramel under the gentle touch of twilight.",
        "A carnival of shadows danced along the deserted boulevard, each step echoing forgotten tales.",
        "In a realm where gravity lost its grip, dreams soared like vivid kites against a starlit backdrop.",
        "The enigmatic street artist splashed abstract dreams onto concrete walls, creating a symphony of colors under midnight skies."
    ]
    
    # Randomly choose one sentence from the list
    sentence = random.choice(sentences)
    
    # Display instructions and the chosen sentence
    print("Typing Speed Tester")
    print("-------------------")
    print("Type the following sentence as quickly and accurately as you can:\n")
    print(sentence + "\n")
    input("Press Enter when you're ready to start...")

    print("\nStart typing below:\n")
    
    # Start the timer and capture the user's input
    start_time = time.time()
    typed_text = input()
    end_time = time.time()
    
    # Calculate elapsed time
    elapsed_time = end_time - start_time

    # Count the number of words in the sentence
    word_count = len(sentence.split())
    
    # Calculate words per minute (WPM)
    wpm = (word_count / elapsed_time) * 60

    print("\nResults:")
    print("Time taken: {:.2f} seconds".format(elapsed_time))
    print("Your typing speed is: {:.2f} words per minute (WPM)".format(wpm))
    
if __name__ == "__main__":
    typing_speed_test()