Python timer countdown

后端 未结 7 818
南方客
南方客 2021-01-16 13:06

I want to know about timer in Python.

Suppose i have a code snippet something like:

def abc()
   print \'Hi\'  
   print \'Hello\'
   print \'Hai\'
<         


        
7条回答
  •  无人共我
    2021-01-16 14:06

    import sys
    import time
    
    c=':'
    sec = 0
    min = 0
    hour = 0
    
    #count up clock
    
    while True:
    for y in range(59):                                                 #hours
        for x in range (59):                                            #min
            sec = sec+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))   #clear and write
            time.sleep(1)
        sec = 0
        sys.stdout.write('\r' + str(hour1) + c + str(min1) + c + '00')  #ensure proper timing and display
        time.sleep(1)
        min=min+1
    min = 0
    sys.stdout.write('\r' + str(hour1) + c + str(min1) + c + '00')      #ensure proper timing and display
    time.sleep(1)
    hour=hour+1
    

提交回复
热议问题