-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockPaperScissors.py
37 lines (29 loc) · 1.04 KB
/
rockPaperScissors.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
35
36
37
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!"
def play_game():
choices = ["rock", "paper", "scissors"]
player_choice = input("Enter your choice (rock/paper/scissors): ").lower()
if player_choice not in choices:
print("Invalid choice. Please choose rock, paper, or scissors.")
return
computer_choice = random.choice(choices)
print(f"Computer chose: {computer_choice}")
result = determine_winner(player_choice, computer_choice)
print(result)
# Main loop
while True:
play_game()
play_again = input("Do you want to play again? (yes/no): ").lower()
if play_again != "yes":
print("Thanks for playing!")
break