![]() |
VOOZH | about |
Rock Paper Scissor (which is also called Stone Paper Scissor) is a hand game and played between two people, in which each player simultaneously forms one of three shapes. The winner of the game is decided as per the below rules:
In this game, the user will be asked to make choice and according to the choice of user and computer and then the result will be displayed along with the choices of both computer and user.
Approach: Below is the functionality that needed to be implemented in the program:
Note: This random number will decide the choice of computer as:
- If the number is between 0-33 then the choice will be Stone.
- If the number is between 33-66 then the choice will be Paper.
- If the number is between 66-100 then the choice will be Scissors.
game() function: This function consists of if-else statements that will compare the choice of user and computer. If the user wins then it will return 1. Otherwise, if the computer wins then it will return 0. If it is a tie, it will return -1.
Below is the implementation of the above approach:
Output: