试图制作2人Rock,Paper,Scissors游戏

时间:2017-04-09 22:01:31

标签: python

#rock,paper,scissors
#inputs of player 1 and player 2
t = ["Rock","Paper","Scissors"]
while p !='x':
  p = raw_input("Player 1, please enter Rock,Paper, or Scissors!")
  if p == 'x':
      break,
while pp !='y':
  pp = raw_input("Player 2, please enter Rock,Paper or Scissors!")
  if p == 'y':
      break,
#player 1 values of choice
if p == "Rock":
    p = 1
elif p == "Paper":
    p = 2
elif p == "Scissors":
    p = 3
else
    print("You have entered a wrong hand")
#player 2 values of choice
if pp == "Rock":
    pp = 1
elif pp == "Paper":
    pp = 2
elif pp == "Scissors":
    pp = 3
#outcomes of the Game
if p > pp
print("Player 1 Wins")
elif p < pp
print("Player 2 Wins")
elif p = pp
print("Players Draw")

我不确定我的代码出了什么问题。有人可以解释我做错了什么。我存储了所有值和输入。然而,它无论如何都无法运行。

2 个答案:

答案 0 :(得分:1)

你的程序中有很多错误,试着找一本关于基本python语法的书,因为在你的程序中,它表明你不知道if else语句的语法(应该有:)和几个错误的缩进,最后程序无法运行,因为你没有定义关于你的程序的单个函数,python不是程序语言,尽管你可以在一个小程序中这样做。

答案 1 :(得分:0)

您似乎错过了很多:并且您没有正确检查输入。这是一个例子:p not in {"Rock", "Paper", "Scissors"}

#rock,paper,scissors
#inputs of player 1 and player 2
t = ["Rock","Paper","Scissors"]
p = ''
pp = ''
while p not in {"Rock", "Paper", "Scissors"}:
  p = raw_input("Player 1, please enter Rock,Paper, or Scissors!")
while pp not in {"Rock", "Paper", "Scissors"}:
  pp = raw_input("Player 2, please enter Rock,Paper or Scissors!")
#player 1 values of choice
if p == "Rock":
    p = 1
elif p == "Paper":
    p = 2
elif p == "Scissors":
    p = 3
else:
    print("You have entered a wrong hand")
#player 2 values of choice
if pp == "Rock":
    pp = 1
elif pp == "Paper":
    pp = 2
elif pp == "Scissors":
    pp = 3
#outcomes of the Game
if p > pp:
    print("Player 1 Wins")
elif p < pp:
    print("Player 2 Wins")
elif p == pp:
    print("Players Draw")