我對Python相當陌生,已經開始製作一些有趣的小遊戲來記住它是如何工作的。我遇到了一個我想在while循環中使用多個條件的區域,並且無法解決如何操作。我在這裏看到過一些人在用數字等來做這件事,但我使用的是字母,沒有做任何事情或搜索似乎都有效。這是迄今爲止我所擁有的。這個想法是,人選擇A或B(大寫或小寫),如果他們不這樣做,它會再次循環輸入。在python的while循環中使用多個條件
ANS = input("\tA/B: ")
if ANS == "A":
print("They beat you up and stole all of your stuff. You should have run away.")
del BAG[:]
print("You now have", len(BAG), "items in your bag.")
elif ANS == "a":
print("They beat you up and stole all of your stuff. You should have run away.")
del BAG[:]
print("You now have", len(BAG), "items in your bag.")
elif ANS == "B":
print("You got away but they stole something from you.")
ran_item = random.choice(BAG)
BAG.remove(ran_item)
print("You now have", len(BAG), "items in your bag")
print("They are:", BAG)
elif ANS == "b":
print("You got away but they stole something from you.")
ran_item = random.choice(BAG)
BAG.remove(ran_item)
print("You now have", len(BAG), "items in your bag")
print("They are:", BAG)
while ANS != "A" or "a" or "B" or "b":
print("You must make a choice...")
ANS = input("\tA/B: ")
任何幫助都會很棒。先謝謝了。
非常感謝大家對我的快速回復和幫助。所有的編輯工作都很有用! – robblockwood