Countdown Clock: 01:05

后端 未结 5 2167
长情又很酷
长情又很酷 2020-12-13 07:31

How can I create a countdown clock in Python that looks like 00:00 (min & sec) which is on a line of its own. Every time it decreases by one actual second then

5条回答
  •  庸人自扰
    2020-12-13 07:56

    Maybe this link will help: Making a Timer in Python 3

    And look at my answer, it is same for your too!

    Anyway, here is answer:

    import time
    import os
    hour = int(input('Enter any amount of hours you want -+==> '))
    minute = int(input('Enter any amount of minutes you want -+==> '))
    second = int(input('Enter any amount of seconds you want -+==> '))
    time = hour*10800 + minute*3600 + second*60
    print('{}:{}:{}'.format(hour,minute,second))
    while time > 0:
       time = time - 1
       seconds = (time // 60) % 60
       minutes = (time // 3600)
       hours = (time // 10800)
       print('Time Left -+==> ',hours,':',minutes,':',seconds,)
       os.system("CLS")
    if time == 0:
       print('Time Is Over!') 
    

    Input:

    Enter any amount of hours you want -+==> 0
    Enter any amount of minutes you want -+==> 0 
    Enter any amount of seconds you want -+==> 10
    

    Output # All are on the same line

    Time Left -+==> 0:0:10
    Time Left -+==> 0:0:9
    Time Left -+==> 0:0:8
    Time Left -+==> 0:0:7
    Time Left -+==> 0:0:6
    Time Left -+==> 0:0:5
    Time Left -+==> 0:0:4
    Time Left -+==> 0:0:3
    Time Left -+==> 0:0:2
    Time Left -+==> 0:0:1
    Time Left -+==> 0:0:0
    Time Is Over!
    

提交回复
热议问题