This question already has answers here:
How to test multiple variables against a value?
(24个答案)
5年前关闭。
我刚开始使用python,但在我的脑海中,有些东西显然应该有用。这是我的第一个代码,我只是尝试与用户进行对话。
我的问题是,即使我用否定的回答来回答,它仍然会用一个回答来回答,好像我说了“是”,如果我把2转过来(所以否定回答的代码高于肯定回答的代码),它总是用一个否定的回答来回答。
或
会成功的
(24个答案)
5年前关闭。
我刚开始使用python,但在我的脑海中,有些东西显然应该有用。这是我的第一个代码,我只是尝试与用户进行对话。
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转过来(所以否定回答的代码高于肯定回答的代码),它总是用一个否定的回答来回答。
最佳答案
if yearlikedislike in ("yes", "Yes", "YES", "yep", "yup", "Yep", "Yup"):
或
if yearlikedislike.lower() in ("yes","yep","yup"):
会成功的
09-27 04:39