Untitled
unknown
plain_text
10 months ago
1.2 kB
3
Indexable
import random
def rock_paper_scissors():
print("Welcome to Rock, Paper, Scissors!")
choices = ["rock", "paper", "scissors"]
while True:
# Get the player's choice
player_choice = input("Enter your choice (rock, paper, scissors) or 'quit' to exit: ").lower()
if player_choice == 'quit':
print("Thanks for playing!")
break
if player_choice not in choices:
print("Invalid choice. Please try again.")
continue
# Randomly select the computer's choice
computer_choice = random.choice(choices)
print(f"Computer chose: {computer_choice}")
# Determine the winner
if player_choice == computer_choice:
print("It's a tie!")
elif (player_choice == "rock" and computer_choice == "scissors") or \
(player_choice == "paper" and computer_choice == "rock") or \
(player_choice == "scissors" and computer_choice == "paper"):
print("You win!")
else:
print("You lose!")
print() # Print a blank line for better readability
if __name__ == "__main__":
rock_paper_scissors()Editor is loading...
Leave a Comment