-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissors.py
95 lines (80 loc) · 2.69 KB
/
rock_paper_scissors.py
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
from random import choice
leader_board = {
"computer": 0,
"you": 0
}
choices = ["Rock", "Paper", "Scissors"]
valid_inputs = ["R","Rock", "P", "Paper", "S", "Scissors", "Q", "Quit"]
def get_user_choice(valid_user_choices=[]):
"""
Get user input choice function..
It MUST be a valid input from the valid_inputs list
:args list()
:returns void
"""
user_choice = False
while not user_choice:
user_choice = input("""
Please enter one of the following choices:
R for Rock
P for Paper
S for Scissors
Q for Quit: """
).title()
if user_choice in valid_user_choices:
return user_choice
else:
user_choice = False
while True:
# get psaudo random computer choice
computer_choice = choice(choices)
# User choice can either be a letter or a word
user_pick = get_user_choice(valid_inputs)
"""
Because user choice can either be a letter or a word,
I created an anonymous function to select a word starting with
a letter x that is more than one character in length.
This way we pick the corresponding word using the given letter.
"""
user_pick = list(filter(lambda x: x.startswith(user_pick) and len(x) > 1, valid_inputs))[0]
print(f"\nComputer: {computer_choice} <-> You: {user_pick}")
if computer_choice == user_pick:
leader_board["computer"] += 1
leader_board["you"] += 1
print(f"It's a tie....\n")
if computer_choice == "Rock" and user_pick == "Scissors":
leader_board["computer"] += 1
print("Rock crushes Scissors....\nYou lose...\n")
if computer_choice == "Scissors" and user_pick == "Rock":
leader_board["you"] += 1
print("Rock crushes Scissors....\nYou win!!!\n")
if computer_choice == "Paper" and user_pick == "Rock":
leader_board["computer"] += 1
print("Paper covers Rock....\nYou lose...\n")
if computer_choice == "Rock" and user_pick == "Paper":
leader_board["you"] += 1
print("Paper covers Rock....\nYou win!!!\n")
if computer_choice == "Scissors" and user_pick == "Paper":
leader_board["computer"] += 1
print("Scissors cuts Paper....\nYou lose...\n")
if computer_choice == "Paper" and user_pick == "Scissors":
leader_board["you"] += 1
print("Scissors cuts Paper....\nYou lose...\n")
if user_pick == "Quit":
print(f"""
LEADER BOARD:
Computer v You
{leader_board['computer']} : {leader_board['you']}
\n
""")
print("Thank you for playing :)\nSee you again next time.")
break
quit = input("Press [any key] to exit\nPress [enter] to replay..\n:")
if len(quit) >= 1:
print(f"""
LEADER BOARD:
Computer v You
{leader_board['computer']} : {leader_board['you']}
\n
""")
break