2016-01-22 89 views
-4

當我運行這段代碼時,我在原始的def函數中得到了冒號的語法錯誤。我老實說不知道爲什麼。def冒號的語法錯誤

#Rock Paper Scissors 
import random; 
def rps: 
    user = input("Enter your choice (rock/paper/scissors): "); 
    user = user.lower(); 
    while (user != "rock" and user != "paper" and user != "scissors"): 
     print(user); 
     user = input("That choice is not valid. Enter your choice (rock/paper/scissors): "); 
     user = user.lower(); 

    computerInt = random.randint(0,2); 
    if (computerInt == 0): 
     computer = "rock"; 
    elif (computerInt == 1): 
     computer = "paper"; 
    elif (computerInt == 2): 
     computer = "scissors"; 
    else: 
     computer = "Error"; 

    if (player == computer): 
     print("Draw!"); 
    elif (player == "rock"): 
     if (computer == "paper"): 
      print("Computer wins!"); 
     else: 
      print("You win!"); 
     elif (player == "paper"): 
      if (computer == "rock"): 
       print("You win!"); 
      else: 
       print("Computer wins!") 
      elif (player == "scissors"): 
       if (computer == "rock"): 
        print("Computer wins!"); 
       else: 
        print("You win!"); 

    print("Your choice: " + player + "\nComputer choice: " + computer + "\nThank you for playing!"); 
    playAgain = input("Would you like to play again? (y/n)"); 
    playAgain = playAgain.lower() 
    if (playAgain == "y"): 
     rps() 
    else: 
     print("Thank you for playing.") 
     input("Press any key to exit") 
+0

函數的名稱後括號沒有'高清FUNC_NAME():#do函數y stuff' –

+0

'''高清RPS() :'''而不是'''def rps:''' –

+0

請將代碼放入問題中,而不是鏈接。在發佈之前花一些時間來減少這個例子。你有46行代碼,並在那裏有一個錯誤...你怎麼做的工作削減下來。 – tdelaney

回答

1

您需要RPS功能加括號:

def rps():