简体   繁体   中英

Add a time delay in python count up function for the multiples of a given number

My function is:

import time

count = int()

while True:
  count += 1
  time.sleep(1)
  if count == 50:
    time.sleep(5)

I need to put a time delay in every multiple of 50.

You can do something like this

import time
for count in range(1000):
    if count %50==0:
        print ('Number divisible by 50')
        time.sleep(5)
import time

count = int()

<
count += 1
do some function
>

if (count % 50) == 0:
  time.sleep(5)

This should do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM