【发布时间】:2021-04-08 11:44:45
【问题描述】:
我有一个不和谐的垃圾邮件机器人。
import pyautogui
from time import sleep
time = 0
while time != 10:
time += 1
sleep(1)
print ("Get Ready" + str (time) )
def spam(msg, maxMsg):
count = 0
while count != maxMsg:
count += 1
print("send message: " + str(count ))
pyautogui.write(msg)
pyautogui.press("enter")
if count == 5 or count == 10 or count == 15:
sleep(8)
spam('Test', 15)
我的问题在于if count,这里的上限是 15,但我希望它是 500,而不写 or count == 20 or count == 25,直到 500 有没有办法说在每个 5 的倍数上睡眠?
【问题讨论】:
-
使用取模运算符。
-
当count除以5时,你可以检查余数是否为0。
if count % 5 == 0: -
if count % 5 == 0 -
你在学走路之前就在跑步。几乎您将遇到的每种编程语言都会有某种模数运算。