diff --git a/INDEX.md b/INDEX.md index c9db9a6..7d9a81a 100644 --- a/INDEX.md +++ b/INDEX.md @@ -79,3 +79,6 @@ By now we have 2 numbers (variables), you and computer ### 🎯 [Whack_A_Mole](./Python/Whack_A_Mole/) - Language: Python + +### 🎯 [Rock–Paper–Scissors](python/rock_paper_scissors/) +- Language: Python diff --git a/Python/rock_paper_scissors/README.md b/Python/rock_paper_scissors/README.md new file mode 100644 index 0000000..83611d3 --- /dev/null +++ b/Python/rock_paper_scissors/README.md @@ -0,0 +1,25 @@ +# 🎮 Rock–Paper–Scissors (Python) + +A simple console-based Rock–Paper–Scissors game written in Python. + +## 🚀 How to Run +```bash +python rock_paper_scissors.py +``` + +## 🧠 Features + +- Player vs Computer mode + +- Randomized computer choice + +- Keeps score + +- Option to quit anytime + + ## Example Output + +Your move (rock/paper/scissors): rock +Computer chose: scissors +✅ You win this round! +Play again? (y/n): y diff --git a/Python/rock_paper_scissors/rock_paper_scissors.py b/Python/rock_paper_scissors/rock_paper_scissors.py new file mode 100644 index 0000000..6d06dd5 --- /dev/null +++ b/Python/rock_paper_scissors/rock_paper_scissors.py @@ -0,0 +1,50 @@ +import random + +def get_computer_choice(): + """Returns rock, paper, or scissors randomly for the computer.""" + return random.choice(["rock", "paper", "scissors"]) + +def determine_winner(player, computer): + """Determines the winner of a round.""" + if player == computer: + return "tie" + elif (player == "rock" and computer == "scissors") or \ + (player == "paper" and computer == "rock") or \ + (player == "scissors" and computer == "paper"): + return "player" + else: + return "computer" + +def main(): + print("🎮 Welcome to Rock–Paper–Scissors! 🎮") + print("Type 'rock', 'paper', or 'scissors'. Type 'q' to quit.\n") + + player_score = 0 + computer_score = 0 + + while True: + player = input("Your move: ").strip().lower() + if player == 'q': + break + if player not in ["rock", "paper", "scissors"]: + print("❌ Invalid input. Try again!\n") + continue + + computer = get_computer_choice() + print(f"Computer chose: {computer}") + + result = determine_winner(player, computer) + if result == "player": + print("✅ You win this round!\n") + player_score += 1 + elif result == "computer": + print("💻 Computer wins this round!\n") + computer_score += 1 + else: + print("🤝 It's a tie!\n") + + print(f"Final Score — You: {player_score}, Computer: {computer_score}") + print("Thanks for playing! 👋") + +if __name__ == "__main__": + main()