Countdown Clock: 01:05

后端 未结 5 2139
长情又很酷
长情又很酷 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条回答
  •  -上瘾入骨i
    2020-12-13 07:45

    import time
    import sys
    
    print(' ')
    print('Countdown Timer, By Adam Gay')
    print(' ')
    print('Instructions: Input time to countdown from.')
    print(' ')
    
    c=':'
    
    hourz=input('Hours: ')
    minz=input('Minutes: ')
    secz=input('Seconds: ')
    print(' ')
    
    hour=int(hourz)
    min=int(minz)
    sec=int(secz)
    
    while hour > -1:
        while min > -1:
            while sec > 0:
                sec=sec-1
                time.sleep(1)
                sec1 = ('%02.f' % sec)  # format
                min1 = ('%02.f' % min)
                hour1 = ('%02.f' % hour)
                sys.stdout.write('\r' + str(hour1) + c + str(min1) + c + str(sec1))
    
            min=min-1
            sec=60
        hour=hour-1
        min=59
    
    Print('Countdown Complete.')
    time.sleep(30)
    

提交回复
热议问题