Stopwatch until correct imput is enterd

42 views Asked by At

I want to make a stopwatch that count how much time it took you to enter a correct imput. Are there modules that can help with is?

I have already tried using import time and import timer I am making a speed typer and i want to know how long it took you to type.

1

There are 1 answers

1
Peter On
from random import * 
from timer import *
import time
list = ["inch","multiply","nothing","course","stay","wheel","full","force","blue","object","decide","surface","deep","moon","island","foot","system","busy","test","record","boat","common","gold","possible","plane","stead","dry","wonder","laugh","thousand","ago","ran","check","game","shape","equate","hot","miss","brought","heat","snow","tire","bring","yes","distant","fill","east","paint","language","among","grand"]
a = randint(0,49)
c = list[a]
# Define the correct input
correct_input = c

# Start measuring time
start_time = time.time()

# Prompt the user for input until they enter the correct one
while True:
    print(c)
    user_input = input("Write the word: ")
    if user_input == correct_input:
        break

# Calculate the time taken
end_time = time.time()
sek = end_time - start_time

print(f"You wrote the word in {sek:.2f} sek.")