-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem 1
29 lines (22 loc) · 1.02 KB
/
Problem 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import random
def determine_winner(user_choice, computer_choice): if user_choice == computer_choice: return "It's a tie!" elif (user_choice == 'rock' and computer_choice == 'scissors') or
(user_choice == 'scissors' and computer_choice == 'paper') or
(user_choice == 'paper' and computer_choice == 'rock'): return "You win!" else: return "Computer wins!"
def main(): choices = ['rock', 'paper', 'scissors']
# Get user's choice
print("Welcome to Rock, Paper, Scissors!")
print("Available choices: rock, paper, scissors")
user_choice = input("Enter your choice: ").lower()
# Validate user input
while user_choice not in choices:
print("Invalid choice. Please enter rock, paper, or scissors.")
user_choice = input("Enter your choice: ").lower()
# Generate computer's choice
computer_choice = random.choice(choices)
# Determine the winner
result = determine_winner(user_choice, computer_choice)
# Print results
print(f"\nYou chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
print(result)
if name == "main": main()