-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathrps3.py
More file actions
58 lines (43 loc) · 1.35 KB
/
rps3.py
File metadata and controls
58 lines (43 loc) · 1.35 KB
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
51
52
53
54
55
56
57
58
import sys
import random
from enum import Enum
def play_rps():
class RPS(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3
playerchoice = input(
"\nEnter... \n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
if playerchoice not in ["1", "2", "3"]:
print("You must enter 1, 2, or 3.")
return play_rps()
player = int(playerchoice)
computerchoice = random.choice("123")
computer = int(computerchoice)
print("\nYou chose " + str(RPS(player)).replace('RPS.', '').title() + ".")
print("Python chose " + str(RPS(computer)
).replace('RPS.', '').title() + ".\n")
if player == 1 and computer == 3:
print("🎉 You win!")
elif player == 2 and computer == 1:
print("🎉 You win!")
elif player == 3 and computer == 2:
print("🎉 You win!")
elif player == computer:
print("😲 Tie game!")
else:
print("🐍 Python wins!")
print("\nPlay again?")
while True:
playagain = input("\nY for Yes or \nQ to Quit\n")
if playagain.lower() not in ["y", "q"]:
continue
else:
break
if playagain.lower() == "y":
return play_rps()
else:
print("\n🎉🎉🎉🎉")
print("Thank you for playing!\n")
sys.exit("Bye! 👋")
play_rps()