当我运行此代码时,我在原始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 :(得分:1)
您需要在rps函数上添加括号:
def rps():