垃圾邮件发送者:输入数字值无效

问题描述

我编写了一个脚本,该脚本向特定文本发送垃圾邮件。我想这样做,因此您可以在cmd提示符下选择要发送的单词和次数。 spam_setup和spam_word_set可以工作。给我一个输入,我可以输入要输入的内容。但是,当我尝试在估算中输入值时,它确实起作用。

## Here is a picture of the error ##

import pyautogui,time
import sys

#Variables
count = 1
sleep_time = 4

spam_word_set = input("Set a word to be spammed: ")
spam_setup = (spam_word_set," ")

loop = input("How many times do you want to send that word: ")

try:
    val = int(loop)
    print("The input is not a  acceptable number. Number = ",val)
except ValueError:
    try:
        val= float(loop)
        print("Input is float number: Correct value [number]")
    except ValueError:
        print("The input is a string. Not a number")


print("Sending",loop,"messages in:",sleep_time,"seconds")
time.sleep(sleep_time) 


for word in spam_setup:
    while count < (loop+1):
        pyautogui.typewrite(word)
        print("Sending message:  ",count,"of",loop)
        pyautogui.press("enter")
        if count == (loop):
            break
        count = (count+1) 

解决方法

您可能打算在这里使用val代替loop

while count < (loop+1):

..所以

while count < (val+1):

..应该可以。但是不要这样做-不需要在循环内进行所有递增和中断操作。取而代之的是,进行一个循环,使其直接循环多次:

for count in range(0,val):
    pyautogui.typewrite(word)
    print("Sending message:  ",count + 1,"of",loop)
    pyautogui.press("enter")
,

loop = input(“您要发送该单词多少次:”)

我认为输入是字符串。尝试将输入字符串转换为int,如下所示:

loop = int(input("How many times do you want to send that word: "))

我不是这方面的专家,但我希望它会有所帮助