Skip to content

A simple Python script to play the classic Rock-Paper-Scissors game. Test your luck and challenge the computer!

License

Notifications You must be signed in to change notification settings

fahadelahikhan/Rock-Paper-Scissors-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rock-Paper-Scissors Python 🪨📄✂️

Python Version License

A simple command-line implementation of the classic Rock-Paper-Scissors game in Python.

📜 About

This project implements the traditional Rock-Paper-Scissors game where players compete against a computer opponent. The game follows standard rules where rock beats scissors, scissors beat paper, and paper beats rock. It's an excellent example of basic game logic and user input handling in Python.

✨ Features

  • Classic Rock-Paper-Scissors gameplay
  • Random computer opponent selection
  • Simple command-line interface
  • Input validation for user choices
  • Clear win/lose/draw conditions

🚀 Quick Start

Installation

  1. Clone the repository:

    git clone https://github.com/fahadelahikhan/Rock-Paper-Scissors-Python.git
    cd Rock-Paper-Scissors-Python
  2. Run the game:

    python "Rock Paper Scissors.py"

Basic Usage

# Import the game function
from rock_paper_scissors import play_game

# Start a new game
play_game()

# Choose your move by entering 0, 1, or 2
# 0 for Rock, 1 for Paper, 2 for Scissors

Example Game Session

# User chooses Paper (1)
user_choice = 1

# Computer randomly selects Rock (0)
computer_choice = 0

# Determine the winner
if (computer_choice == 0 and user_choice == 1):
    print("You Win!")
elif (computer_choice == user_choice):
    print("Draw!")
else:
    print("You lose!")

# Display choices
print(f"Your choice is: {Expression[user_choice]}")
print(f"Computer choice is: {Expression[computer_choice]}")

📖 How It Works

The game logic is based on simple conditional statements:

  • If the user's choice beats the computer's choice according to standard rules, the user wins
  • If both choices are the same, it's a draw
  • Otherwise, the computer wins

The computer's choice is generated using Python's random.randint(0, 2) function, ensuring a fair random selection.

⚖️ License

Distributed under the MIT License. See LICENSE for details.


Note: This implementation is for educational and entertainment purposes. The game uses a simple random algorithm for the computer opponent, which is not cryptographically secure.

About

A simple Python script to play the classic Rock-Paper-Scissors game. Test your luck and challenge the computer!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages