I'm new to Python and recently coded a rock-paper-scissors game as a learning exercise. My goal was to get more familiar with the random function and conditional statements. I'd love to get some feedback on my code โ are there ways I could make it more efficient or improve its readability?
Here's the code:
`import random
paper_opt = "Paper"
scissors_opt = "Scissors"
rock_opt = "Rock"
options = [paper_opt, scissors_opt, rock_opt]
while True:
user_choice = input(f"please pick between {paper_opt}. {scissors_opt} or {rock_opt} :")
if user_choice.lower() == paper_opt.lower():
print(f"You played {paper_opt}")
break
elif user_choice.lower() == scissors_opt.lower():
print(f"You played {scissors_opt}")
break
elif user_choice.lower() == rock_opt.lower():
print(f"You played {rock_opt}")
break
else:
print("Invalid choice. please pick Paper, Scissors or Rock")
opponent_choice = random.choice(options)
print(f"The opponent played {opponent_choice}")
if user_choice.lower() == opponent_choice.lower():
print("It's a tie!")
elif (user_choice.lower() == "paper") and opponent_choice.lower() == "rock" or
(user_choice.lower() == "rock") and opponent_choice.lower() == "scissors" or
(user_choice.lower() == "scissors") and opponent_choice.lower() == "paper":
print("You Win!")
else:
print("You Lose!")`