-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathrps.py
More file actions
39 lines (29 loc) · 818 Bytes
/
rps.py
File metadata and controls
39 lines (29 loc) · 818 Bytes
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
import sys
import random
from enum import Enum
class RPS(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3
print("")
playerchoice = input(
"Enter...\n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
player = int(playerchoice)
if player < 1 or player > 3:
sys.exit("You must enter 1, 2, or 3.")
computerchoice = random.choice("123")
computer = int(computerchoice)
print("")
print("You chose " + str(RPS(player)).replace('RPS.', '') + ".")
print("Python chose " + str(RPS(computer)).replace('RPS.', '') + ".")
print("")
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!")