0
keyCounter = 0
key1Value = 0
key2Value = 0
key3Value = 0
print(key1Value)
key1Value = input("Press the first key.")
key2Value = input("Press the second key.")
key3Value = input("Press the third key.")
# password = 123
if key1Value == 1 and key2Value == 2 and key3Value == 3:
print("Access Granted")
print(key1Value)
print(key2Value)
print(key3Value)
elif key1Value != 1 and \
key2Value != 2 and \
key3Value != 3:
print("Access Denied")
print(key1Value)
print(key2Value)
print(key3Value)
else:
print("Vault error")
print(key1Value)
print(key2Value)
print(key3Value)
input("Press Enter to continue...")
爲什麼總是導致「Vault Error」?我環顧四周,我覺得如果條件不對,但我不確定。如果語句幫助Python
因爲'input'總是返回一個字符串。換句話說,你試圖比較'1'和''1''。使用'int(input(「按第一個鍵。」))'。 – roganjosh
如果你輸入一個類似'126'的代碼(其中兩個值匹配,但一個不匹配),你會得到一個「Vault Error」而不是「Access Denied」。如果*號碼不匹配,您只會看到「訪問被拒絕」。我不確定這是否是您正在尋找的結果。這可能不是問題,但我只想指出:'key1Value == 1和key2Value == 2和key3Value == 3'的倒數實際上是'key1Value!= 1或key2Value!= 2或key3Value != 3'(這是由於[德摩根法律](https://en.wikipedia.org/wiki/De_Morgan%27s_laws))。 –