“elif”在“while”循环中不工作

2024-10-01 11:25:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个程序;但是,即使输入了“y”或“yes”,代码仍然会进入“n”/“no”循环。有什么建议吗?在

no = input("How many messages?")
intNo = int(no)
msgno = input("2 different msgs? [y/n]:")
message = input("Message:")
message2 = input("Message 2:")

run = True
pyautogui.click(x=980, y=805, button='left')
while run == True:
    if msgno.lower() == "n" or "no":
        pyautogui.typewrite(message, interval=0.00001)
        pyautogui.press('enter')
        intNo = intNo - 1
        if intNo <= 0:
            run = False
    elif msgno.lower() == "y" or "yes":
        no = no / 2
        pyautogui.typewrite(message, interval=0.00001)
        pyautogui.press('enter')
        pyautogui.typewrite(message2, interval=0.00001)
        pyautogui.press('enter')
        intNo = intNo - 1
        if intNo <= 0:
            run = False

Tags: norunmessageinputifyespressenter
1条回答
网友
1楼 · 发布于 2024-10-01 11:25:58

必须在每个If语句中添加两个条件语句。像这样:if msgo.lower() == 'yes' or msgo.lower() == 'y'如果只存在一个变量或一个值,它将默认为True,因此“no”默认为True并进入代码块。在

相关问题 更多 >