-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps.py
More file actions
105 lines (78 loc) · 2.71 KB
/
rps.py
File metadata and controls
105 lines (78 loc) · 2.71 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
import random
from enum import Enum
def rps(name='PlayerOne'):
game_count = 0
player_wins = 0
python_wins = 0
def play_rps():
nonlocal name
nonlocal player_wins
nonlocal python_wins
class RPS(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3
playerchoice = input(
f"\n{name}, please enter... \n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
if playerchoice not in ["1", "2", "3"]:
print(f"{name}, please enter 1, 2, or 3.")
return play_rps()
player = int(playerchoice)
computerchoice = random.choice("123")
computer = int(computerchoice)
print(f"\n{name}, you chose {str(RPS(player)).replace('RPS.', '').title()}.")
print(
f"Python chose {str(RPS(computer)).replace('RPS.', '').title()}.\n"
)
def decide_winner(player, computer):
nonlocal name
nonlocal player_wins
nonlocal python_wins
if player == 1 and computer == 3:
player_wins += 1
return f"🎉 {name}, you win!"
elif player == 2 and computer == 1:
player_wins += 1
return f"🎉 {name}, you win!"
elif player == 3 and computer == 2:
player_wins += 1
return f"🎉 {name}, you win!"
elif player == computer:
return "😲 Tie game!"
else:
python_wins += 1
return f"🐍 Python wins!\nSorry, {name}..😢"
game_result = decide_winner(player, computer)
print(game_result)
nonlocal game_count
game_count += 1
print(f"\nGame count: {game_count}")
print(f"\n{name}'s wins: {player_wins}")
print(f"\nPython wins: {python_wins}")
print(f"\nPlay again, {name}?")
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(f"Bye {name}! 👋")
return play_rps
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Provides a personalized game experience."
)
parser.add_argument(
"-n", "--name", metavar="name",
required=True, help="The name of the person playing the game."
)
args = parser.parse_args()
rock_paper_scissors = rps(args.name)
rock_paper_scissors()