-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock_Paper_Scissor_Game.py
45 lines (34 loc) · 1.33 KB
/
Rock_Paper_Scissor_Game.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
38
39
40
41
42
43
44
45
import random
def get_computer_choice():
choices = ['rock', 'paper', 'scissors']
return random.choice(choices)
def get_user_choice():
user_choice = input(
"Enter your choice (rock, paper, or scissors): ").lower()
while user_choice not in ['rock', 'paper', 'scissors']:
user_choice = input(
"Invalid choice. Please enter rock, paper, or scissors: ").lower()
return user_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 "You lose!"
def play_game():
print("Welcome to Rock, Paper, Scissors!")
while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"\nYou chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
print(determine_winner(user_choice, computer_choice))
play_again = input("\nDo you want to play again? (yes/no): ").lower()
if play_again != 'yes':
break
print("Thanks for playing!")
if __name__ == "__main__":
play_game()