我只是想知道为什么这行不通,当我对输入说“ n”或“否”时是否可以正常工作,但是当我对输入说“ y”或“是”时,它却做同样的事情至于“不”。程序中的所有其他内容都可以完美运行。我绝对不知道为什么会这样。
def restart():
replay = input("Do you want to restart? (Y/N): ")
if replay.lower() == "n" or "no":
print("exiting")
sys.exit()
if replay.lower() == "y" or "yes":
calc()
else:
print("Unknown Command")
restart()
restart()
替换为:
if replay.lower() == "n" or "no":
print("exiting")
sys.exit()
if replay.lower() == "y" or "yes":
calc()
使用此:
if replay.lower() == "n" or replay.lower() == "no":
print("exiting")
sys.exit()
if replay.lower() == "y" or replay.lower() == "yes":
calc()