Python program to implement Rock Paper Scissor game (original) (raw)

Last Updated : 15 Jun, 2026

Rock-Paper-Scissors is a Python project where player selects one of three options: Rock, Paper, or Scissors. The computer simultaneously makes a random selection. The program compares both choices using the game rules and declares the winner. The game can be played repeatedly until the user decides to quit.

**Example:

1. User Choice: Rock
Computer Choice: Scissors

Result: User Wins

2. User Choice: Paper
Computer Choice: Paper

Result: Draw

Winning Rules

In this game, randint() built-in function is used for generating random integer values within the given range.

Algorithm

  1. Display the rules of the game.
  2. Accept the user's choice.
  3. Validate the input and ensure it is within the allowed options.
  4. Generate the computer's choice randomly.
  5. Compare both choices and determine the winner.
  6. Display the result of the round.
  7. Ask the user whether they want to play again.
  8. Repeat the game until the user chooses to exit.

Implementation

Python `

import random

Display game rules

print("Welcome to Rock-Paper-Scissors!\n") print("Winning Rules:") print("Rock vs Paper -> Paper wins") print("Rock vs Scissors -> Rock wins") print("Paper vs Scissors -> Scissors wins\n")

choices = ["Rock", "Paper", "Scissors"]

while True:

print("Choose an option:")
print("1 - Rock")
print("2 - Paper")
print("3 - Scissors")

# Validate user input
try:
    choice = int(input("Enter your choice: "))
except ValueError:
    print("Please enter a valid number.\n")
    continue

while choice < 1 or choice > 3:
    choice = int(input("Please enter a valid choice (1-3): "))

# User choice
user_choice = choices[choice - 1]

print("\nUser choice is:", user_choice)
print("Now it's Computer's Turn...")

# Computer choice
comp_choice = random.randint(1, 3)
computer_choice = choices[comp_choice - 1]

print("Computer choice is:", computer_choice)
print(user_choice, "vs", computer_choice)

# Determine winner
if choice == comp_choice:
    print("<== It's a Tie! ==>")

elif (
    (choice == 1 and comp_choice == 3) or
    (choice == 2 and comp_choice == 1) or
    (choice == 3 and comp_choice == 2)
):
    print("<== User Wins! ==>")

else:
    print("<== Computer Wins! ==>")

# Play again
while True:
    ans = input("\nDo you want to play again? (Y/N): ").lower()

    if ans in ['y', 'n']:
        break

    print("Please enter Y or N.")

if ans == 'n':
    break

print()

print("\nThanks for playing!")

`

**Output:

Winning rules of the game ROCK PAPER SCISSORS are:
Rock vs Paper -> Paper wins
Rock vs Scissors -> Rock wins
Paper vs Scissors -> Scissors wins

Enter your choice
1 - Rock
2 - Paper
3 - Scissors

Enter your choice:
1 - Rock
2 - Paper
3 - Scissors

Enter your choice: 1

User choice is: Rock
Computer choice is: Scissors

<== User wins! ==>

Do you want to play again? (Y/N)
N

Thanks for playing!

**Explanation: