Create rock_paper_scissors.py
Browse files- rock_paper_scissors.py +32 -0
rock_paper_scissors.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
|
3 |
+
def get_choices():
|
4 |
+
player_choice = input("Enter a choice (rock, paper, scissors): ")
|
5 |
+
options = ["rock", "paper", "scissors"]
|
6 |
+
computer_choice = random.choice(options)
|
7 |
+
choices = {"player": player_choice, "computer": computer_choice}
|
8 |
+
return choices
|
9 |
+
|
10 |
+
def check_win(player, computer):
|
11 |
+
print(f"You chose {player}, computer chose {computer}")
|
12 |
+
if player == computer:
|
13 |
+
return "It's a tie!"
|
14 |
+
elif player == "rock":
|
15 |
+
if computer == "scissors":
|
16 |
+
return "Rock smashes scissors! You win!"
|
17 |
+
else:
|
18 |
+
return "Paper covers rock! You lose."
|
19 |
+
elif player == "paper":
|
20 |
+
if computer == "rock":
|
21 |
+
return "Paper covers rock! You win!"
|
22 |
+
else:
|
23 |
+
return "Scissors cuts paper! You lose."
|
24 |
+
elif player == "scissors":
|
25 |
+
if computer == "paper":
|
26 |
+
return "Scissors cuts paper! You win!"
|
27 |
+
else:
|
28 |
+
return "Rock smashes scissors! You lose."
|
29 |
+
|
30 |
+
choices = get_choices()
|
31 |
+
result = check_win(choices["player"], choices["computer"])
|
32 |
+
print(result)
|