2017-04-09 4 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") 

私のコードで何がうまくいかないのか分かりません。誰かが私が間違ったことを説明することはできますか?私はすべての値を格納し、入力します。しかし、それはまったく実行されません。2人の岩、紙、はさみの試行をしようとする

+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

あなたのプログラムのエラーの多くは、あなたのプログラムでは、それはあなたが(持っている必要がある場合はelse文の構文を知らない示すことから、基本的なPythonの構文についての本を探してみてください: )といくつかの間違ったインデントがあり、最後にプログラムに関する単一の関数を定義していないため、プログラムを実行できませんでした。

関連する問題