-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathrps4.py
More file actions
70 lines (50 loc) · 1.6 KB
/
rps4.py
File metadata and controls
70 lines (50 loc) · 1.6 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
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import random
from enum import Enum
game_count = 0
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")
def decide_winner(player, computer):
if player == 1 and computer == 3:
return "🎉 You win!"
elif player == 2 and computer == 1:
return "🎉 You win!"
elif player == 3 and computer == 2:
return "🎉 You win!"
elif player == computer:
return "😲 Tie game!"
else:
return "🐍 Python wins!"
game_result = decide_winner(player, computer)
print(game_result)
global game_count
game_count += 1
print("\nGame count: " + str(game_count))
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()