Python 3.x Python 3;石头剪刀-只是不断选择一个结果
写一个小RPS游戏,我遇到了一个问题 1) 当我运行函数玩游戏时,它总是以“平局”的形式返回 即使我选择了一个失败的变量,比如cpu=石头,玩家=剪刀 我有点被难住了。当我遇到麻烦时,我通常潜伏在stackoverflow论坛,但我从未遇到过有同样问题的人(即使这里有太多的RPS问题) 现在,我不是要求任何人为我编写并100%测试它,而是告诉我错误点,我会去排除故障 谢谢Python 3.x Python 3;石头剪刀-只是不断选择一个结果,python-3.x,Python 3.x,写一个小RPS游戏,我遇到了一个问题 1) 当我运行函数玩游戏时,它总是以“平局”的形式返回 即使我选择了一个失败的变量,比如cpu=石头,玩家=剪刀 我有点被难住了。当我遇到麻烦时,我通常潜伏在stackoverflow论坛,但我从未遇到过有同样问题的人(即使这里有太多的RPS问题) 现在,我不是要求任何人为我编写并100%测试它,而是告诉我错误点,我会去排除故障 谢谢 def showRules(): print("********** Rock, Paper, Scissors *
def showRules():
print("********** Rock, Paper, Scissors **********")
print("Rules: Each player chooses either Rock, Paper, or Scissors.")
print(" The winner is determined by the following rules:")
print(" Scissors cuts Paper -> Scissors wins")
print(" Paper covers Rock -> Paper Wins")
print(" Rock smashes Scissors -> Rock Wins")
print("*******************************************")
def getCPUChoice():
choices = ["rock", "paper", "scissors"]
from random import randint
randNum = randint(0,2)
cpuchoice = choices[randNum]
print(cpuchoice)
return
def getUserChoice():
choices = ["rock", "paper", "scissors"]
userchoice = input('Please choose either rock, paper or scissors:').lower()
print(userchoice)
return
def declareWinner(user, computer):
if user == computer:
print("Tie!!")
elif user == "rock" and computer == "paper":
print("You lose!")
elif user == "paper" and computer == "scissors":
print("You lose!")
elif user == "scissors" and computer == "rock":
print("You lose!")
def playGame():
showRules()
computer = getCPUChoice()
user = getUserChoice()
declareWinner(user, computer)
在getCPUChoice和getUserChoice中,您正在打印选择而不是返回它们。将这些函数末尾的返回值更改为
return cpuchoice
及
分别。在任何情况下都不返回任何内容。。。因此user=None,computer=None。谢谢!我让它工作了。现在,只是为了让它更具审美吸引力。
return userchoice