-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockPaperScissorsGame.py
More file actions
48 lines (48 loc) · 1.73 KB
/
rockPaperScissorsGame.py
File metadata and controls
48 lines (48 loc) · 1.73 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
# Import module
import random
# Init constants
OPTIONS_ARRAY = ["Rock", "Paper", "Scissors"]
# Init variables
player_score = 0
player_option = "undefined"
opponent_score = 0
opponent_option = "undefined"
# Init functions
def check_eligibility(option):
for option_instance in OPTIONS_ARRAY:
if (option_instance == option):
return True
return False
pass
def score_to_score():
return str(player_score) + "|" + str(opponent_score)
pass
# Game load
print("ROCK PAPER SCISSORS")
print("Pick among Rock, Paper, or Scissors.")
print("Rock beats Scissors, Scissors beats Paper, and Paper beats Rock.")
input("Press enter to begin the game. ")
player_score = 0
opponent_score = 0
# Game loop
while True:
print("# New Round:")
opponent_option = OPTIONS_ARRAY[random.randint(0, 2)]
player_option = input("Rock, Paper, Scissors: ")
if (check_eligibility(player_option)):
if (player_option == opponent_option):
print(player_option + " is also " + opponent_option + " - Round tied: " + score_to_score())
else:
if ((player_option == "Rock" and opponent_option == "Scissors") or
(player_option == "Paper" and opponent_option == "Rock") or
(player_option == "Scissors") and opponent_option == "Paper"):
player_score += 1
print(player_option + " beats " + opponent_option + " - Player Wins: " + score_to_score())
else:
opponent_score += 1
print(player_option + " loses to " + opponent_option + " - Opponent Wins: " + score_to_score())
pass
else:
print("Ineligible input - Round skipped: " + score_to_score())
pass
pass