Untitled
unknown
python
3 years ago
2.0 kB
4
Indexable
import sys attempts_player1 = 0; attempts_player2 = 0; def RPSValidate(playerchoice): answers = ["rock","paper","scissors"] if playerchoice not in answers: return ("input error") else: return playerchoice.lower() def RPSExecute(player1, player2): if (player1 == player2): print("The game is a draw because both player 1 and 2 chose:", player1) return 0 elif (player1 == "rock"): if (player2 == "paper"): return 2 elif (player2 == "scissors"): return 1 elif (player1 == "paper"): if (player2 == "rock"): return 1 elif (player2 == "scissors"): return 2 elif (player1 == "scissors"): if (player2 == "rock"): return 2 elif (player2 == "paper"): return 1 print("Welcome to Rock, Paper, Scissors: ") print("Player 1, type 'rock', 'paper', or 'scissors'") player1 = input().lower() player1 = RPSValidate(player1) while player1 == "input error": print('Player 1 input is incorrect. Enter input again ') player1 = input().lower() player1 = RPSValidate(player1) attempts_player1 += 1 if attempts_player1 == 3: sys.exit() print("Player 2, type 'rock', 'paper', or 'scissors'") player2 = input().lower() player2 = RPSValidate(player2) while player2 == "input error": print('Player 2 input is incorrect. Enter input again ') player2 = input().lower() player2 = RPSValidate(player2) attempts_player2 += 1 if attempts_player2 == 3: sys.exit() winner = RPSExecute(player1, player2) if (winner == 0): print("The game is a draw because both player 1 and 2 chose:", player1) elif (winner == 1): print("Player 1 wins because they chose: ", player1) elif (winner == 2): print("Player 2 wins because they chose: ", player2)
Editor is loading...