How to make a timer program in Python

前端 未结 11 2237
予麋鹿
予麋鹿 2021-02-08 14:24

Here is my goal: To make a small program (text based) that will start with a greeting, print out a timer for how long it has been since the last event, and then a timer for the

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 14:58

    The ideas are pretty cool on other posts -- however, the code was not useable for what I wanted to do.

    I liked how people want to subtract time, in this way you don't have to have a time.sleep()

    from datetime import datetime
    
    timePoint = time.time()
    count = 0
    while (count < 10):
        timePoint2 = time.time()
        timePointSubtract = timePoint2 - timePoint
        timeStamp1 = datetime.utcfromtimestamp(timePointSubtract).strftime('%H:%M:%S')
        print(f'{count} and {timeStamp1}')
        val = input("")
        count = count + 1
    

    So, pretty much I wanted to have a timer but at the same time keep track of how many times I pressed enter.

提交回复
热议问题