-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrps.py
More file actions
27 lines (23 loc) · 1012 Bytes
/
rps.py
File metadata and controls
27 lines (23 loc) · 1012 Bytes
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
import random
def determine_winner(player_choice, computer_choice):
if player_choice == computer_choice:
return "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"):
return "You win!"
else:
return "Computer wins!"
choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)
while True:
player_choice = input("Choose rock, paper, or scissors: ").lower()
if player_choice not in choices:
print("Invalid choice. Please choose rock, paper, or scissors.")
else:
result = determine_winner(player_choice, computer_choice)
print(f"Computer chose {computer_choice}. {result}")
play_again = input("Do you want to play again? (yes/no): ").lower()
if play_again != "yes":
break
computer_choice = random.choice(choices)