Solution
Hints
- Python's random module can pick a random number for you -- look up random.randint().
- Use int() to convert the player's typed input into a number you can compare.
- Check for a tie first (both pick the same number) before checking who wins.
Steps
- Import the random module.
- Ask for and store the player's choice as an integer.
- Generate the computer's choice with random.randint(1, 3).
- Print both choices by name so the player can see what happened.
- Use if/elif/else to check for a tie, then check the three ways the player can win, otherwise the computer wins.
import random
CHOICES = {1: "Rock", 2: "Paper", 3: "Scissors"}
player = int(input("Choose 1-Rock, 2-Paper, or 3-Scissors: "))
computer = random.randint(1, 3)
print(f"You chose {CHOICES[player]}. Computer chose {CHOICES[computer]}.")
if player == computer:
print("It's a tie!")
elif (
(player == 1 and computer == 3) or
(player == 2 and computer == 1) or
(player == 3 and computer == 2)
):
print("You win!")
else:
print("Computer wins!")