使用python sh结束whileloop

2024-09-27 00:17:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试制作一个秒表,我的同事们要求我制作它,但我希望它能够在我在python shell中键入某个键时停止计时器。你知道吗

import time

timer = 0
timeTrueFalse = True

startTimer = input("Type start if you want to start!")

if (startTimer == "start"):
    while timeTrueFalse:
            timer = (timer + 1)
            print (timer)
            time.sleep(1)

Tags: importtrueinput键入iftimetypeshell
1条回答
网友
1楼 · 发布于 2024-09-27 00:17:42

你可以使用时间戳

import time

while not str(raw_input("write start: ")) == "start" :
    pass

tstamp=time.time()

while not str(raw_input("write stop: ")) == "stop" :
    pass    

delta=time.time()-tstamp

#delta has the time in seconds.

相关问题 更多 >

    热门问题