Skip to content
Open
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
9 changes: 9 additions & 0 deletions Rock-Paper-Scissors/README.md
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions Rock-Paper-Scissors/main.py
Original file line number Diff line number Diff line change
@@ -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()
Loading