Create a ROCK- PAPER-SCISSORS Game with Python

Create a ROCK- PAPER-SCISSORS Game with Python

This post will explore how to create a minimal rock-paper-scissor. However, before we make the game, we should understand what a rock-paper-scissors game is about.

Rock, paper, scissors is a classic game of chance for two people. You and a partner shake your fists three times and then make gestures at random to show a rock, paper, or scissors. Rock beats scissors, scissors beat paper, and paper beats rock (it wraps the rock!).

Now that we understand the game and how to play it. We will break down the logic to code the game.

  1. import random modules; this gives us random functionality
  2. The game needs two players, a user and a computer
  3. The computer has three choices stored in a list container
  4. The computer randomly picks one of the choices in the list of container
  5. A users choice is stored in a variable
  6. An IF logic is used to check for computers choice and users the choice to determine a Winner or a Tie
import random

# Printing a  header and welcome message
print('*'*50)
print('Welcome to Rock, Paper & Scissors Game')
print('*'*50)
#The computer has three choices stored in a list container
computer_choice = ['SCISSORS', 'ROCK', 'PAPER']

#The computer randomly picks one of the choices in the list of container
computer_choices = random.choice(computer_choice)

#A users choice is stored in a variable
user_choice = str(input('Do you want - Rock, Paper, or Scissors?: '))
user_choice = user_choice.upper()
if computer_choices == user_choice:
    print("It's a TIE. You have chosen", user_choice, "and Computer has chosen,", computer_choices)
    print()

elif user_choice == 'ROCK' and computer_choices == 'SCISSORS':
    print(" YOU WIN !!! | You Chose", user_choice, 'and Computer has chosen', computer_choices)

elif user_choice == 'PAPER' and computer_choices == 'ROCK':
    print(" YOU WIN !!! | You Chose", user_choice, 'and Computer has chosen', computer_choices)

elif user_choice == 'SCISSORS' and computer_choices == 'PAPER':
    print(" YOU WIN !!! | You Chose", user_choice, 'and Computer has chosen', computer_choices)
else:
    print("Sorry You lose !!! | You Chose", user_choice, 'and Computer has chosen', computer_choices)

image.png

Congratulations, you have just built your first rock-paper-scissors game; here is a link to my GitHub for the updated version of this game.