我剛剛開始使用python,並且陷入了一些在我看來應該工作的東西。這是我的第一個代碼,我只是試圖與用戶進行對話。Python - if語句工作不正確
year = input("What year are you in school? ")
yearlikedislike = input("Do you like it at school? ")
if (yearlikedislike == "yes" or "Yes" or "YES" or "yep" or "yup" or "Yep" or "Yup"):
print("What's so good about year " + year, "? ")
input("")
print("That's good!")
time.sleep(1)
endinput = input("I have to go now. See you later! ")
exit()
if (yearlikedislike == "no" or "No" or "nope" or "Nope" or "NOPE"):
print("What's so bad about year " + year, "?")
input("")
time.sleep(1)
print("Well that's not very good at all")
time.sleep(1)
endinput = input("I have to go now. See you later! ")
time.sleep(1)
exit()
我的問題是,即使我一個否定的答案回答它仍然可以與響應,如果我說是的答覆,如果我切換2左右(所以對於否定答案的代碼是上面的代碼爲正面答案),它總是會回覆,就好像我已經給出了否定的答覆。
+1打我吧:) –
您可能也想介紹'str。低' – iCodez
同意。 YEP和YUP錯過了,更不用說其他組合了。 – mhlester