2017-04-09 87 views
-2
#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") 

我不确定我的代码出了什么问题。有人能解释我做错了什么吗?我有所有的值存储和输入。但它不会运行。试图制作一名玩家Rock,Paper,Scissors游戏

+0

while方法不是必需的,因为它们p和pp总是“x”和“y” –

+0

无处不在的语法和缩进错误! –

回答

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") 
1

很多程序中的错误,试图找到一本关于基本Python语法,因为在你的程序中,它显示了你不知道有关的if else语句的语法(应具备: )和几个错误缩进,最后程序无法运行,因为您没有定义关于程序的单个函数,python不是一种过程语言,尽管您可以在一个小程序中这样做。