# FILE: rock_paper_scissors.py
import random
def game(your_choice: int) -> list:
"""
Function to play a single round of Rock-Paper-Scissors game.
Parameters:
your_choice (int): The player's choice. Should be an integer between 0 and 2,
where 0 represents 'rock', 1 represents 'paper', and
2 represents 'scissors'.
Returns:
list: A list containing the results of the game round.
The list elements are as follows:
1. The player's choice.
2. The computer's choice.
3. The result of the round, which can be one of the following strings:
- "Tie🤝" if the player and computer made the same choice.
- "You won" if the player's choice beats the computer's choice.
- "You lost" if the player's choice loses to the computer's choice.
"""
choices = ["rock", "paper", "scissors"]
computer_choice = random.randint(0, 2)
# Create a dictionary to map the player's and computer's choices to outcomes
outcomes = {
(0, 0): "It's a Tie",
(0, 1): "You lost",
(0, 2): "You won",
(1, 0): "You won",
(1, 1): "It's a Tie",
(1, 2): "You lost",
(2, 0): "You lost",
(2, 1): "You won",
(2, 2): "It's a Tie",
}
result = [f"Your choice:\n{choices[your_choice]}", f"Computer's choice:\n{choices[computer_choice]}", outcomes[(your_choice, computer_choice)]]
return result
Comments