forked from Kushal-Pareek/CodeRed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissor.py
More file actions
75 lines (67 loc) · 2.2 KB
/
rock_paper_scissor.py
File metadata and controls
75 lines (67 loc) · 2.2 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
import random
# Function to take input from the player
def getPlayer():
player = "empty"
player = input("Please Enter You Choice - Rock | Paper | Scissor = ")
while not (player == "Rock" or player == "Paper" or player == "Scissor"):
player = input("Please Enter You Choice - Rock | Paper | Scissor = ")
return player
# Function to generate input from the bot
def getBot():
lst = ["Rock", "Scissor", "Paper"]
return random.choice(lst)
# Function to match the inputs
def getWinner(player, bot):
if player == "Rock" and bot == "Rock":
return "Draw"
elif player == "Rock" and bot == "Paper":
return "Bot"
elif player == "Rock" and bot == "Scissor":
return "Player"
elif player == "Paper" and bot == "Paper":
return "Draw"
elif player == "Paper" and bot == "Rock":
return "Player"
elif player == "Paper" and bot == "Scissor":
return "Bot"
elif player == "Scissor" and bot == "Scissor":
return "Draw"
elif player == "Scissor" and bot == "Paper":
return "Player"
elif player == "Scissor" and bot == "Rock":
return "Bot"
else:
return "DRAW"
# Main Function
def start():
print("Rock Paper Scissors!\n")
gameBegins()
# To begin game
def gameBegins():
# To end the game if user wants
endTheGame = "n"
# For storing score
player_score = 0
bot_score = 0
# Running the game till user wants
while endTheGame.lower() != "y":
player = getPlayer()
bot = getBot()
print("You Played -", player)
print("Bot Played -", bot)
winneris = getWinner(player=player, bot=bot)
print("The Winner is - ", winneris)
if winneris == "Player":
player_score += 2
elif winneris == "Bot":
bot_score += 2
else:
player_score += 1
bot_score += 1
print("-----Score Board-----")
print("-----Player-----", player_score)
print("-----Bot-----", bot_score)
print(" ")
endTheGame = input("You wish to end? Choose Y/N: ")
print("\nThank you for Playing!")
start()