Display a countdown for the python sleep function

后端 未结 7 1178
一生所求
一生所求 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:43

    Here's one I did:

    import time
    a = input("How long is the countdown?")
    while a != 0:
        print a
        time.sleep(1)
        a = a-1
    

    At the end if you and an else you can put an alarm or whatever.

提交回复
热议问题