How to make a timer program in Python

前端 未结 11 2242
予麋鹿
予麋鹿 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 15:08

    # This Is the Perfect Timer!(PS: This One Really Works!)
    import sys
    import time
    import os
    
    counter=0
    s = 0
    m = 0
    n = int(input("Till How Many Seconds do you want the timer to be?: "))
    print("")
    
    while counter <= n:
        sys.stdout.write("\x1b[1A\x1b[2k")
        print(m, 'Minutes', s, 'Seconds')
        time.sleep(1)
        s += 1
        counter+=1
        if s == 60:
            m += 1
            s = 0
    
    print("\nTime Is Over Sir! Timer Complete!\n")
    

提交回复
热议问题