這是我做的一個簡單的游戲,我想增加能夠再次游戲的選項,而不必反復運行程式。然而,每當我試圖這樣做時,它似乎沒有考慮或達到我代碼底部的 "elif "陳述句。我怎樣才能讓它作業呢?
import random
from time import sleep as wait
# Definition of variables.變數的定義。
choices = [
"rock"。
"紙"。
"scissors".
]
ai = random.choice(choice)
player = input("enter rock, paper, or scissors: ").lower()
while True。
for i in range(2147483647)。
# Makes sure the player type in something from the choices..
if player not in choices:
print("
無效! 輸入一個有效的選擇。(檢查你的拼寫!)")
wait(0.5)
player = input("
輸入石頭、紙、或剪刀。").lower()
else:
print(f"
你選了{player}。")
break。
wait(1)
print(f"
ai挑選{ai}。
")
wait(1)
# 每個可能的解決方案的選擇。
if player == "rock" in choices and ai == "paper" in choices:
print("ai用紙覆寫你。(Lose)")
elif player == "rock" in choicesand ai == "scissors" in choices:
print("You beat the ai's scissors to a plump. (贏)")
elif player == "rock" in choicesand ai == "rock" in choices:
print("Y'all are beating each other with a rock, and no one wins. (平局)")
elif player == "paper" in choicesand ai == "rock" in choices:
print("You cover ai's rock in paper. (贏)")
elif player == "paper" in choicesand ai == "paper" in choices:
print("你們兩個人都試圖用紙覆寫對方,沒完沒了。(打結)")
elif player == "paper" in choicesand ai == "scissors" in choices:
print("ai cut you to pieces! (Lose)")
elif player == "scissors" in 在選擇 和 ai == "rock" 在選擇。
print("ai用石頭把你的剪刀打到豐滿。(輸了)")
elif player == "scissors" in choices and ai == "paper" in choices:
print("You cut ai to pieces! (贏)")
elif player == "scissors" in choicesand ai == "scissors" in choices:
print("Y'all try to cut each other's metal somehow, endlessly. (綁)")
else:
# This is in case the player found a bug.。
print("How did we get here?" )
wait(1)
again = input("
你想再玩一次嗎?(是/否)。
").降低
# Start of problem ---------------------------------------------------。
if again == "yes" or "ye" or "y"。
ai = random.choice(choice)
player = input("enter rock, paper, or scissors: ").lower()
繼續。
elif again == "no" or "n":
break break
# End of problem -----------------------------------------------------
uj5u.com熱心網友回復:
again = input("
你想再玩一次嗎?(是/否)。
").降低
這應該是個錯字,lower應該是lower()
。 if again == "yes" or "ye" or "y"
條件可能是不恰當的,你可能需要知道什么是運算子的優先級 https://docs.python.org/3/reference/expressions.html#operator-precedence
我建議你可以用
if再次 in ["yes", "ye","y"】。]
uj5u.com熱心網友回復:
if again == "yes" or "ye" or "y"。
應該像
一樣if again == "yes"/span> or again == "ye" or again =="y"。
否則,它就會像這樣評估為真
if "ye":
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/314487.html
標籤:
下一篇:將兩個虛擬變數合并為一個新變數
