-1
私は勝利/損失のためのポイントシステムを実装しようとしている間に、パイソンでロックペーパーはさみゲームを作ろうとしています。私はコードを実行すると、私はロックペーパーやハサミを選択するように求められる、私は私の答えを選ぶが、私は再び何か理由で尋ねられる、誰かが私を助けることができる?これらの行で(Iかなりの初心者です)Pythonコードは2回実行されます
from random import randint
def RPS():
UserPts = 0
AIPts = 0
def Game():
moves = ["Rock","Paper","Scissors"]
def genAImove():
genai = moves[randint(0,2)]
return genai
genAImove()
AImove = genAImove()
def genUserMove():
genu = raw_input("Choose your move ('Rock','Paper' or 'Scissors')\n")
return genu
genUserMove()
UserMove = genUserMove()
if UserMove == "Rock" and AImove == "Rock":
print "The AI chose rock too.\nDraw."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Rock" and AImove == "Paper":
print "The AI chose paper.\nLoss."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Rock" and AImove == "Scissors":
print "The AI chose scissors.\nWin."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Paper" and AImove == "Rock":
print "The AI chose rock.\nWin."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Paper" and AImove == "Paper":
print "The AI chose paper.\nDraw."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Paper" and AImove == "Scissors":
print "The AI chose scissors.\nLoss."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Scissors" and AImove == "Rock":
print "The AI chose rock.\nLoss."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Scissors" and AImove == "Paper":
print "The AI chose paper.\nWin."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
if UserMove == "Scissors" and AImove == "Scissors":
print "The AI chose scissors.\nDraw."
def cont():
cnt = raw_input("Do you want to continue? (Y\N)")
if cnt == "Y":
Game()
elif cnt == "N":
exit
else:
print "Pick Y or N"
cont()
cont()
Game()
RPS()
すばやく対応いただきありがとうございます。問題は解決しました。私はグローバル変数が実際にどのように働いていたのか分からなかったので、私はこれをもっと複雑にしました。なぜなら、関数内で関数を作ったのですが、同じグローバル変数問題を見つけ、それをもう少し調べて間違いを実感しました。必要以上に多くのコードが必要ですが、ポイントもあります。 – dragoljub