Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions Python/rock_paper_scissors/README.md
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions Python/rock_paper_scissors/rock_paper_scissors.py
Original file line number Diff line number Diff line change
@@ -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()
Loading