From dec31dc2664e2dd0a9c9e571cbdc4508c5a36566 Mon Sep 17 00:00:00 2001 From: honey-khatri Date: Wed, 22 Oct 2025 23:47:18 +0530 Subject: [PATCH] added rockpaperscissor --- .../Programs/Python/rockpaper/README.md | 33 ++++++++++ .../Programs/Python/rockpaper/rockpaper.py | 62 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/Python/rockpaper/README.md create mode 100644 Domains/CompetitiveProgramming/Programs/Python/rockpaper/rockpaper.py diff --git a/Domains/CompetitiveProgramming/Programs/Python/rockpaper/README.md b/Domains/CompetitiveProgramming/Programs/Python/rockpaper/README.md new file mode 100644 index 00000000..1008dc1d --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/rockpaper/README.md @@ -0,0 +1,33 @@ +**contributor** honey-khatri + +# ✊✋✌️ Rock Paper Scissors — Python Console Game + +This is a simple and interactive Rock-Paper-Scissors game built in Python. It runs in the console and lets you play against the computer with ASCII art visuals for each move. Great for beginners learning Python basics like loops, conditionals, and input handling. + +--- + +## 🎮 How to Play + +- Run the script in any Python environment. +- Choose your move by typing: + - `0` for Rock + - `1` for Paper + - `2` for Scissors +- The computer randomly selects its move. +- The game displays both choices using ASCII art and announces the winner. +- You can play multiple rounds until you choose to exit. + +--- + +## 🛠️ Requirements + +- Python 3.x +- No external libraries needed + +--- + +## 📦 Installation & Run + +1. Clone the repository: + ```bash + git clone https://github.com/honey-khatri/rock-paper-scissors.git \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/Python/rockpaper/rockpaper.py b/Domains/CompetitiveProgramming/Programs/Python/rockpaper/rockpaper.py new file mode 100644 index 00000000..7f43de96 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/rockpaper/rockpaper.py @@ -0,0 +1,62 @@ +import random + +rock = """ + _______ +---' ____) + (_____) + (_____) + (____) +---.__(___) +""" + +paper = """ + _______ +---' ____)____ + ______) + _______) + _______) +---.__________) +""" + +scissors = """ + _______ +---' ____)____ + ______) + __________) + (____) +---.__(___) +""" + +game_images = [rock, paper, scissors] + +while True: + user_choice_input = input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors: ") + + try: + user_choice = int(user_choice_input) + except ValueError: + print("Invalid input. Please type 0, 1, or 2.") + continue + + if user_choice < 0 or user_choice >= 3: + print("You typed an invalid number, you lose!") + else: + print("You chose:") + print(game_images[user_choice]) + + computer_choice = random.randint(0, 2) + print("Computer chose:") + print(game_images[computer_choice]) + + if user_choice == computer_choice: + print("It's a draw!") + elif (user_choice == 0 and computer_choice == 2) or \ + (user_choice == 1 and computer_choice == 0) or \ + (user_choice == 2 and computer_choice == 1): + print("You win!") + else: + print("You lose!") + + play_again = input("Do you want to play again? (yes/no): ").lower() + if play_again != 'yes': + break \ No newline at end of file