forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock Paper Scissors - New Version
50 lines (40 loc) · 1.47 KB
/
Rock Paper Scissors - New Version
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
46
47
48
49
50
import random
def get_user_choice():
choices = ["rock", "paper", "scissors", "lizard", "spock"]
user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower()
while user_choice not in choices:
user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower()
return user_choice
def get_computer_choice():
choices = ["rock", "paper", "scissors", "lizard", "spock"]
return random.choice(choices)
def determine_winner(user_choice, computer_choice):
win_conditions = {
"scissors": ["paper", "lizard"],
"paper": ["rock", "spock"],
"rock": ["lizard", "scissors"],
"lizard": ["spock", "paper"],
"spock": ["scissors", "rock"]
}
if user_choice == computer_choice:
return "tie"
elif computer_choice in win_conditions[user_choice]:
return "user"
else:
return "computer"
def play_game():
print("Welcome to Rock, Paper, Scissors, Lizard, Spock!")
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f"You chose: {user_choice}")
print(f"Computer chose: {computer_choice}")
winner = determine_winner(user_choice, computer_choice)
if winner == "tie":
print("It's a tie! Let's play again.")
play_game()
elif winner == "user":
print("You win!")
else:
print("Computer wins!")
if __name__ == "__main__":
play_game()