-2

I am trying to create a stopwatch that starts and stops through the user pressing the enter. Once to start and again to stop. The start works perfectly but the stopping section is not working. I've tried creating a variable called stop that is like so:

stop = input("stop?")

But it's still not working.

import time
def Watch():
        a = 0
        hours = 0
        while a < 1:
            for minutes in range(0, 60):
                for seconds in range(0, 60):
                    time.sleep(1)
                    print(hours,":", minutes,":", seconds)
                hours = hours + 1
def whiles():
    if start == "":
        Watch()
    if start == "":
        return Watch()    
def whiltr():
    while Watch == True:
            stop = input("Stop?")

#Ask the user to start/stop stopwatch
print ("To calculate your speed, we must first find out the time that you       have taken to drive from sensor a to sensor b, consequetively for six drivers.")
start = input("Start?")
start = input("Stop")
whiles()
user
  • 5,370
  • 8
  • 47
  • 75
  • 1
    Your `whiles` function makes no sense; why do you call `Watch` twice? Also, you've got a conceptual problem here: once you call `Watch` you're forever stuck in the `while` loop inside of the function and all code after it is never reached. You need to run the stopwatch code in a separate thread so that your main thread isn't blocked; and you need to create a `Watch` object which you can control. As both threading and classes are huge topics, I've voted to close the question as too broad. I'd suggest you read a few threading tutorials first, the official one is a good start. – l4mpi Feb 18 '15 at 12:47

2 Answers2

0

Perhaps all you need is something simple like:

import time

input('Start')
start = time.time()
input('Stop')
end = time.time()

print('{} seconds elapsed'.format(end-start))
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
0

Should probably use the time function instead of

def Watch():