Rock, Paper and Scissors Game Using Python

Rock, Paper and Scissors Game Using Python

How to build Rock, paper and Scissors Game using python

Rock,paper and Scissors is one of the commonest game kids play, it is very easy and interesting to play. the game is usually between two players where each player make a guess and the winner is known.

How to play Rock, paper and Scissors Game

like I said earlier the game is very easy all that the players need is to choose between the the three options( Scissor, Player, Rock). the winner is know by the follow rules

Rules to declare the winner

  1. if a player pick scissors and the opponent pick paper. then the one who pick scissors is the winner. because scissors cut paper.
  2. if a player pick rock and the opponent pick scissors. then the one who pick rock is the winner. because rock break scissors
  3. if a player picks paper and the opponent pick rock. then the one who picks paper is the winner. because paper covered rock.

    Rule for Draw i.e (no winner)

    Both player will have draw if and only if they both picks the same thing. i.e
  4. if a player picks scissors and the opponent picks Scissors too. no one is the winner
  5. if a player picks rock and the opponent picks rock. then scissors too. no one is the winner.
  6. if a player picks paper and the opponent picks paper. then no one is the winner.

Now let's go in to the codes. here we are going to write codes for the where by the computer will be the opponent of any player.

Important thing to be noted while writing the codes

  1. we will need to import random library in fact almost all game required that. Why random in the codes?? well, the main reason why we need random library is because the computer will also have to pick a choice among the three option and which should not be fixed to one otherwise the player will able to know how to beat the computer.
  2. we will need a list that will stored all the option
  3. we need to do comparison between the player's choice and computer's choice.
  4. we decide who win using some of the rule I have listed above. Here is how our codes look below

Codes>>

import random
playAgain='yes'
option=['Paper','Rock','Scissors']
playerScore=0 # initial score
computerScore=0 # initial score
while playAgain=='yes' or playAgain=='Yes' or playAgain=='Y':
    playerChoice=str(input('Paper Rock or Scissors?? pick one: ')) # ask for player op
    computer=random.choice(option)
    if playerChoice==computer: # if the player and computer picked the same thing
        print('Draw!') #result for equal choice 
    elif playerChoice=='Scissors' and computer=='Rock':
        print('You loose', 'Rock crack Scissors') #result
        computerScore+=1 #add 1 to computer score
    elif computer=='Scissors' and playerChoice=='Rock':
        print('You win', 'Rock crack Scissors')
        playerScore+=1 # add 1 to player score
    elif playerChoice=='Paper' and computer=='Rock':
        print('You win', 'Paper cover Rock')
        playerScore+=1 # add 1 to player's score
    elif computer=='Paper' and playerChoice=='Rock':
        print('You loose', 'Rock crack Scissors')
        computerScore+=1 # add 1 to computer's score
    elif playerChoice=='Paper' and computer=='Scissors':
        print('You Loose', 'Scissors cut Paper')
        computerScore+=1 # add 1 to computer's score
    elif computer=='Paper' and playerChoice=='Scissors':
        print('You Win', 'Scissors cut Paper')
        playerScore+=1 # add 1 to player's score
    continueGame=str(input('did you want to play again: '))
    playAgain=continueGame
print('\nTHE FINAL SCORE') # print the final score
print('computerScore: ',computerScore)
print('Your Score: ',playerScore)

now our codes end here, we can now try to run the codes and see the result. the following show my result after playing three times.

Result>>

Paper Rock or Scissors?? pick one: Rock
You win Rock crack Scissors
did you want to play again: Yes
Paper Rock or Scissors?? pick one: Scissors
You Win Scissors cut Paper
did you want to play again: Yes
Paper Rock or Scissors?? pick one: Rock
Draw!
did you want to play again: no

THE FINAL SCORE
computerScore:  0
Your Score:  2

can you see the result?? that is a simple way to build the game. You can use the same method to create a game for two player instead of