A simple command-line implementation of the classic Rock-Paper-Scissors game in Python.
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.
- Classic Rock-Paper-Scissors gameplay
- Random computer opponent selection
- Simple command-line interface
- Input validation for user choices
- Clear win/lose/draw conditions
-
Clone the repository:
git clone https://github.com/fahadelahikhan/Rock-Paper-Scissors-Python.git cd Rock-Paper-Scissors-Python
-
Run the game:
python "Rock Paper Scissors.py"
# 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
# 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]}")
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.
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.