Reference no: EM131716373
Rock-paper-scissors is a game played between two people, in which each player chooses rock, paper or scissors. The player who chooses rock will beat another player who has chosen scissors ("rock crushes scissors") but will lose to one who has chosen paper ("paper covers rock"). A play of paper will lose to a play of scissors ("scissors cut paper"). If both players make the same choice, the game is tied. Write a Python program for two players to play a rock-paper-scissors game. The program first asks player 1 to enter 'r' for rock, 'p' for paper or 's' for scissors. Use an input validation loop to check player 1's choice immediately. If player 1 has entered an invalid choice (i.e., choice that is not 'r', 'p' nor 's'), ask player 1 to re-enter his choice repeatedly until the choice entered is valid. Do the same for player 2. Then compare the chices entered by the two players and display the result of the game ("Player 1 wins", "Player 2 wins" or "Tie").
The following is an example:
Player 1 - Enter r for rock, p for paper, s for scissors: RInvalid inputPlayer 1 - Enter r for rock, p for paper, s for scissors: rPlayer 2 - Enter r for rock, p for paper, s for scissors: xInvalid inputPlayer 2 - Enter r for rock, p for paper, s for scissors: yInvalid inputPlayer 2 - Enter r for rock, p for paper, s for scissors: pPlayer 2 wins.