-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathrps2.py
More file actions
51 lines (36 loc) · 1.16 KB
/
rps2.py
File metadata and controls
51 lines (36 loc) · 1.16 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
import sys
import random
from enum import Enum
class RPS(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3
playagain = True
while playagain:
playerchoice = input(
"\nEnter... \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("\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!")
playagain = input("\nPlay again? \nY for Yes or \nQ to Quit \n\n")
if playagain.lower() == "y":
continue
else:
print("\n🎉🎉🎉🎉")
print("Thank you for playing!\n")
playagain = False
sys.exit("Bye! 👋")