【发布时间】:2016-01-13 04:13:46
【问题描述】:
编写一个小型 RPS 游戏时遇到了问题。
1) 当我运行该函数玩游戏时,它总是以“平局”的形式返回 即使我选择了一个失败的变量 ex。 cpu = 石头,玩家 = 剪刀
我对此感到有些困惑。当我遇到麻烦时,我通常会潜伏在 stackoverflow 论坛上,但我还没有遇到遇到同样问题的人(即使这里有过多的 RPS 问题)。
现在,我不是要求任何人为我编写和测试它 100%,而只是告诉我错误点,我会去解决问题。
谢谢!
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)
【问题讨论】:
-
在任何情况下都不会返回任何内容...因此 user = None,computer = None 也是如此。
标签: python-3.x