import random
# Rules of the game
print("""ROCK PAPER SCISSORS
Rules of The Game:
Rock beats Scissors.
Paper beats Rock.
Scissors beat Paper.
""")
# Dictionary
number_dict = {
1: "Rock",
2: "Paper",
3: "Scissors"
}
while True:
try:
# User picks
user_pick = int(input("""1. Rock
2. Paper
3. Scissors
Your Pick: """))
# Validate user input
if user_pick < 1 or user_pick > 3:
print("Invalid choice. Please enter a number between 1 and 3.")
continue
user_pick_result = number_dict[user_pick]
print("You picked: {}.".format(user_pick_result))
# Computer picks
computer_pick = random.randint(1, 3)
computer_pick_result = number_dict[computer_pick]
print("Computer Picks: {}".format(computer_pick_result))
# Decide winner
if user_pick == computer_pick:
print("Tie!")
elif (user_pick == 1 and computer_pick == 3) or (user_pick == 2 and computer_pick == 1) or (user_pick == 3 and computer_pick == 2):
print("You win!")
else:
print("Computer wins!")
# Ask for replay
play_again = input("Do you want to play again? (y/n): ")
if play_again.lower() != 'y':
break
except ValueError:
print("Invalid input. Please enter a valid number.")