-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRock_Paper_Scissors.py
34 lines (29 loc) · 1.18 KB
/
Rock_Paper_Scissors.py
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
30
31
32
33
34
import random
def get_user_choice():
user_choice = input("Choose Rock, Paper, or Scissors: ").strip().lower()
while user_choice not in ["rock", "paper", "scissors"]:
print("Invalid choice. Please choose Rock, Paper, or Scissors.")
user_choice = input("Choose Rock, Paper, or Scissors: ").strip().lower()
return user_choice
def get_computer_choice():
choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)
return computer_choice
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 == "paper" and computer_choice == "rock") or \
(user_choice == "scissors" and computer_choice == "paper"):
return "You win!"
else:
return "Computer wins!"
def play_game():
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"You chose {user_choice}.")
print(f"The computer chose {computer_choice}.")
result = determine_winner(user_choice, computer_choice)
print(result)
if __name__ == "__main__":
play_game()