import random
def rock_paper_scissors():
choices = ["rock", "paper", "scissors"]
while True:
user = input("Choose rock, paper, or scissors: ").lower()
if user not in choices:
print("Invalid choice.")
continue
computer = random.choice(choices)
print(f"Computer chose {computer}.")
if user == computer:
print("Tie!")
elif (user == "rock" and computer == "scissors") or (user == "paper" and computer == "rock") or (user == "scissors" and computer == "paper"):
print("You win!")
else:
print("You lose!")
if input("Play again? (y/n): ").lower() != "y":
break
rock_paper_scissors()
Comments
Post a Comment