我正在尝试用python制作一个石头布剪刀游戏,同时尝试实现一个胜负点数系统。当我运行代码,我被要求选择石头布或剪刀,我选择我的答案,但后来我又被问了一些原因,有人能帮我吗?(我基本上是个初学者)
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()
在这些行中:
首先调用
genUserMove
,它会询问您,然后再调用它,并分配结果。你知道吗把第一行去掉。你知道吗
相关问题 更多 >
编程相关推荐