停止秒表

时间:2015-02-18 12:30:55

标签: python input python-3.4

我正在尝试创建一个秒表,通过用户按下回车来启动和停止。一旦开始再次停止。开始工作完美,但停止部分不起作用。我尝试创建一个名为stop的变量,如下所示:

stop = input("stop?")

但它仍无效。

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()

2 个答案:

答案 0 :(得分:0)

也许您需要的只是简单的事情:

import time

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

print('{} seconds elapsed'.format(end-start))

答案 1 :(得分:0)

应该使用时间函数而不是

def Watch():