Computer Science | Artificial Intelligence | Computational Biology | Chess | Blender
import random def get_computer_choice(): choices = ["rock", "paper", "scissors"] return random.choice(choices) def get_user_choice(): user_choice = input("Enter your choice (rock, paper, scissors): ").lower() while user_choice not in ["rock", "paper", "scissors"]: print("Invalid choice. Please try again.") user_choice = input("Enter your choice: ").lower() return user_choice def determine_winner(user, computer): if user == computer: return "It's a tie!" elif (user == "rock" and computer == "scissors") or \ (user == "scissors" and computer == "paper") or \ (user == "paper" and computer == "rock"): return "You win!" else: return "You lose!" def play_game(): print("Welcome to Rock, Paper, Scissors!") while True: user_choice = get_user_choice() computer_choice = get_computer_choice() print(f"\nYou chose: {user_choice}") print(f"Computer chose: {computer_choice}") result = determine_winner(user_choice, computer_choice) print(result) play_again = input("\nDo you want to play again? (yes/no): ").lower() if play_again != "yes": print("Thanks for playing! Goodbye!") break # Run the game play_game()