use*_*600 2 python if-statement
我刚刚开始使用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()
Run Code Online (Sandbox Code Playgroud)
我的问题是,即使我回答否定答案,它仍然会回复一个回复,好像我说的是,如果我切换2(所以否定答案的代码高于肯定答案的代码)它总会回复,好像我给出了否定回复.
if yearlikedislike in ("yes", "Yes", "YES", "yep", "yup", "Yep", "Yup"):
Run Code Online (Sandbox Code Playgroud)
要么
if yearlikedislike.lower() in ("yes","yep","yup"):
Run Code Online (Sandbox Code Playgroud)
会做的