2017-04-09 80 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不是一種過程語言,儘管您可以在一個小程序中這樣做。