Python loop to run for certain amount of seconds

后端 未结 6 1417
萌比男神i
萌比男神i 2020-12-02 22:08

I have a while loop, and I want it to keep running through for 15 minutes. it is currently:

while True:
    #blah blah blah

(this runs thro

6条回答
  •  孤城傲影
    2020-12-02 22:43

    try this:

    import time
    import os
    
    n = 0
    for x in range(10): #enter your value here
        print(n)
        time.sleep(1) #to wait a second
        os.system('cls') #to clear previous number
                         #use ('clear') if you are using linux or mac!
        n = n + 1
    

提交回复
热议问题