From 8cd5113e3007024dd7d6058f97229517d7149f55 Mon Sep 17 00:00:00 2001 From: AkashGowdaNC Date: Tue, 22 Sep 2026 14:30:33 +0530 Subject: [PATCH 1/2] Add main.py for Rock Paper Scissors game --- Rock-Paper-Scissors/main.py | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Rock-Paper-Scissors/main.py diff --git a/Rock-Paper-Scissors/main.py b/Rock-Paper-Scissors/main.py new file mode 100644 index 0000000..968e37b --- /dev/null +++ b/Rock-Paper-Scissors/main.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +""" +main.py +A simple Rock Paper Scissors game against the computer. +The player picks rock, paper, or scissors and plays against a random computer choice. +""" + +import random + + +def get_winner(player: str, computer: str) -> str: + """Return 'player', 'computer', or 'tie' based on the two choices.""" + if player == computer: + return "tie" + if (player == "rock" and computer == "scissors") or \ + (player == "paper" and computer == "rock") or \ + (player == "scissors" and computer == "paper"): + return "player" + return "computer" + + +def main() -> None: + """Run the game loop.""" + choices = ["rock", "paper", "scissors"] + player_score = 0 + computer_score = 0 + + print("Rock Paper Scissors") + print("--------------------") + print("Type 'quit' to exit.\n") + + while True: + player_input = input("Choose rock, paper, or scissors: ").strip().lower() + + if player_input == "quit": + print("\nThanks for playing!") + print(f"Final score: You {player_score} - {computer_score} Computer") + break + + if player_input not in choices: + print("Invalid choice. Try again.\n") + continue + + computer_choice = random.choice(choices) + print(f"Computer chose: {computer_choice}") + + result = get_winner(player_input, computer_choice) + + if result == "tie": + print("It's a tie!\n") + elif result == "player": + print("You win this round!\n") + player_score += 1 + else: + print("Computer wins this round.\n") + computer_score += 1 + + +if __name__ == "__main__": + main() \ No newline at end of file From 0ffa9d413c3f260f0492ffbe3cfdb918ab08d76e Mon Sep 17 00:00:00 2001 From: AkashGowdaNC Date: Tue, 22 Sep 2026 14:30:34 +0530 Subject: [PATCH 2/2] Add README for Rock Paper Scissors game --- Rock-Paper-Scissors/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Rock-Paper-Scissors/README.md diff --git a/Rock-Paper-Scissors/README.md b/Rock-Paper-Scissors/README.md new file mode 100644 index 0000000..c863126 --- /dev/null +++ b/Rock-Paper-Scissors/README.md @@ -0,0 +1,9 @@ +# Rock Paper Scissors + +A simple command-line Rock Paper Scissors game where you play against the computer. + +## How to Run + +```bash +cd Rock-Paper-Scissors +python main.py \ No newline at end of file