问题描述
去年我一直断断续续地使用 Python,并在 YouTube 上发现了一个“垃圾邮件程序”,然后我尝试对其进行重写,以便它重复指定的数量。但是即使我输入一个五,程序仍然只会写一次然后退出。而且我不知道我做错了什么。
import pyautogui
import time
f = open("E:\Documents\Coding-Projekte\Python\Spammer\spamtext",'r')
count = int(input("How often to write the text: "))
time.sleep(5)
def spam():
print("Start Spam")
if count > 0:
for word in f:
if ":" in word:
pyautogui.typewrite(word)
pyautogui.press("enter")
time.sleep(0.5)
pyautogui.press("enter")
count - 1
print("wrote line")
spam()
else:
pyautogui.typewrite(word)
pyautogui.press("enter")
count - 1
print("wrote line")
spam()
else:
exit()
spam()
解决方法
将 if count > 0:
替换为 for repetition in range(count):
。