我正在尝试创建一个程序;但是,即使输入'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
答案 0 :(得分:2)
您必须为每个If语句添加两个条件语句。像这样:if msgo.lower() == 'yes' or msgo.lower() == 'y'
如果你只有一个存在的变量或一个值,它将默认为True,所以“no”默认为True并进入代码块。