任何人都可以幫助我理解爲什麼我非常簡單的岩石剪刀代碼卡在第18行末尾並退出? 我已經測試過每個部分單獨和它的工作,它可能不是最漂亮的代碼,但它似乎做的工作,但在它的最新itteration它只是退出第18行,退出代碼0,所以沒有錯誤,一點兒也不說什麼是錯的,它只是doesn't執行下一行,就像看到一隻破或該線路上的退出,但有isn't:爲什麼我的python代碼沒有完全運行
import random
def startgame():
print("Please choose rock - r, paper - p or scissors - s:")
pchoice = input(str())
if(pchoice.lower in ["r","rock"]):
pchoice = "0"
elif(pchoice.lower in ["s","scissors"]):
pchoice = "1"
elif(pchoice.lower in ["p","paper"]):
pchoice = "2"
cchoice = (str(random.randint(0,2)))
if(cchoice == "0"):
print("Computer has chosen: Rock \n")
elif(cchoice == "1"):
print("Computer has chosen: Scissors \n")
elif(cchoice == "2"):
print("Computer has chosen: Paper \n")
#runs perfect up to here, then stops without continuing
battle = str(pchoice + cchoice)
if(battle == "00" and "11" and "22"):
print("Draw! \n")
playagain()
elif(battle == "02" and "10" and "21"):
if(battle == "02"):
print("You Lose! \nRock is wrapped by paper! \n")
elif(battle == "10"):
print("You Lose! \nScissors are blunted by rock! \n")
elif(battle == "21"):
print("You Lose! \nPaper is cut by scissors! \n")
playagain()
elif(battle == "01" and "12" and "20"):
if(battle == "01"):
print("You Win! \nRock blunts scissors! \n")
elif(battle == "12"):
print("You Win! \nScissors cut paper! \n")
elif(battle == "20"):
print("You Win! \nPaper wraps rock! \n")
playagain()
def main():
print("\nWelcome to Simon´s Rock, Paper, Scissors! \n \n")
startgame()
def playagain():
again = input("Would you like to play again? y/n \n \n")
if(again == "y"):
startgame()
elif(again == "n"):
print("Thank you for playing")
exit()
else:
print("Please choose a valid option...")
playagain()
main()
嘗試打印戰鬥值,並將其與連續if語句中的內容進行比較。 –
你有沒有重複這個問題的條目? – Miket25
提供的代碼有很多問題。有些已經在答案中解釋過,有些則不是。例如,無論你有'.lower'還是'.upper',都應該是'lower()'和'upper()'。否則,這些「if」條件永遠不會是「真」。 – DeepSpace