Display a countdown for the python sleep function

后端 未结 7 1140
一生所求
一生所求 2020-12-30 02:27

I am using time.sleep(10) in my program. Can display the countdown in the shell when I run my program?

>>>run_my_program()
tasks done, now sleeping          


        
7条回答
  •  一生所求
    2020-12-30 02:45

    This is something that I've learned at one of my first python lessons, we played with ["/","-","|","\","|"] but the principle is the same:

    import time
    
    for i in reversed(range(0, 10)):
        time.sleep(1)
        print "%s\r" %i,
    

提交回复
热议问题