0

I am trying to stop a timer when user input is entered

Ex. Someone enters a string, hits enter, and then the timer stops and records the amount of time it took for that string to be entered

Here is what i have so far, but it isn't right.

import time

count=0
stopthetimer = -1
while stopthetimer <0:
    time.sleep(1)
    count +=1
    result = raw_input()
    stopthetimer +=1

tried to make it so when result is finished, it goes to stopthetimer, which stops the loop.

1 Answer 1

6

Just record the time before and after the raw_input() call:

import time

before = time.time()
result = raw_input()
after = time.time()

time_user_input = after-before
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.