【发布时间】:2013-01-16 04:24:42
【问题描述】:
好吧,我的代码可以正常工作,但是当我想重新输入密码时键入 No 时,它不起作用;它只是进入输入密码行(第 20 行)。我尝试了多种方法来解决这个问题,但我根本做不到。
import time
import os
print ("Hello world.")
time.sleep(1)
print ("Waiting 5 seconds.")
time.sleep(5)
print ("You have waited 10 seconds.")
print ("Executing Chrome.")
time.sleep(1)
print ("Execution failed!")
password = input("Enter the execution password: ")
if password == 'password1234':
os.system ('C:\\Users\\Harry\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe')
else:
print ("Wrong password!")
time.sleep(1)
passretry = input("Do you want to try again? ")
if passretry == 'yes' or 'Yes':
passretry1 = input("Enter password: ")
if passretry1 == 'password1234':
os.system ('C:\\Users\\Harry\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe')
elif passretry == 'no' or 'No':
print ("Closing...")
time.sleep(1)
else:
print ("Wrong password.")
time.sleep(.5)
print ("Retry limit exceeded, closing.")
time.sleep(1)
【问题讨论】:
-
有人需要列出常见的 Python 误解。
if a == x or y的主题将位于列表顶部。 -
@MarkRansom:已经有一些这样的列表(即使是常见问题解答也有一个),但出于某种原因,这似乎并没有出现在他们身上……
-
@MarkRansom - 这种误解很常见的不仅仅是 python
标签: python if-statement