Untitled
unknown
plain_text
2 years ago
1.1 kB
4
Indexable
# Import necessary modules import random # Create a list of possible outcomes outcomes = ["rock", "paper", "scissors"] # Create a function to play the game def play_game(): # Prompt the user to enter their choice user_choice = input("Enter your choice (rock, paper, scissors): ") # Check if the user's choice is valid if user_choice not in outcomes: print("Invalid choice. Please try again.") return # Generate a random choice for the computer computer_choice = random.choice(outcomes) # Compare the user's choice and the computer's choice # and determine the winner if user_choice == computer_choice: print("It's a tie!") elif user_choice == "rock" and computer_choice == "scissors": print("You win!") elif user_choice == "paper" and computer_choice == "rock": print("You win!") elif user_choice == "scissors" and computer_choice == "paper": print("You win!") else: print("You lose!") # Start the game play_game()
Editor is loading...