mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Rock-Paper-Scissor Game (#202)
* Rock-Paper-Scissor-Game * updated README.md
This commit is contained in:
parent
e5864acaf9
commit
8ddae6b56f
|
@ -171,6 +171,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[Independent RSA Communication Algorithm](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/RSA_Communication)|[Miguel Santos](https://github.com/wi6n3l)
|
||||
|[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/GithubBot)|[Abhilasha](https://github.com/Abhilasha06)|
|
||||
|[Translate CLI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TranslateCLI)|[Rodrigo Oliveira](https://github.com/rodrigocam)|
|
||||
|[Rock-Paper-Scissor Game](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Rock-Paper-Scissor)|[Punit Sakre](https://github.com/punitsakre23)|
|
||||
|
||||
|
||||
## How to use :
|
||||
|
|
13
Rock-Paper-Scissor/README.md
Normal file
13
Rock-Paper-Scissor/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Python Rock-Paper-Scissor GAME
|
||||
|
||||
The Python script shows the easy to understand and executable program which is used to play the rock-paper-scissor game with scorecard and wish to start or exit.
|
||||
|
||||
## Requirement
|
||||
|
||||
Python 3.xx
|
||||
|
||||
## Running the script
|
||||
|
||||
```bash
|
||||
python Rock-Paper-Scissor.py
|
||||
```
|
102
Rock-Paper-Scissor/Rock-Paper-Scissor.py
Normal file
102
Rock-Paper-Scissor/Rock-Paper-Scissor.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# In[1]:
|
||||
|
||||
|
||||
import random
|
||||
|
||||
|
||||
def takePlayerInput():
|
||||
player = "blank"
|
||||
while not (player.lower() == "r" or player.lower() == "p" or player.lower() == "s"):
|
||||
player = input("Please Enter your input out of - R | P | S = ")
|
||||
return player.lower()
|
||||
|
||||
|
||||
# In[2]:
|
||||
|
||||
|
||||
takePlayerInput()
|
||||
|
||||
|
||||
# In[3]:
|
||||
|
||||
|
||||
def getBotInput():
|
||||
lst = ["r", "s", "p"]
|
||||
return random.choice(lst)
|
||||
|
||||
|
||||
# In[4]:
|
||||
|
||||
getBotInput()
|
||||
|
||||
|
||||
# In[5]:
|
||||
|
||||
|
||||
def checkWinner(player, bot):
|
||||
if player == "r" and bot == "r":
|
||||
return "Draw"
|
||||
elif player == "r" and bot == "p":
|
||||
return "Bot"
|
||||
elif player == "r" and bot == "s":
|
||||
return "Player"
|
||||
elif player == "p" and bot == "p":
|
||||
return "Draw"
|
||||
elif player == "p" and bot == "r":
|
||||
return "Player"
|
||||
elif player == "p" and bot == "s":
|
||||
return "Bot"
|
||||
elif player == "s" and bot == "s":
|
||||
return "Draw"
|
||||
elif player == "s" and bot == "p":
|
||||
return "Player"
|
||||
elif player == "s" and bot == "r":
|
||||
return "Bot"
|
||||
else:
|
||||
return "DRAW"
|
||||
|
||||
|
||||
# In[6]:
|
||||
|
||||
|
||||
checkWinner("s", "p")
|
||||
|
||||
|
||||
# In[7]:
|
||||
|
||||
|
||||
def rockPaperScissor():
|
||||
endTheGame = "n"
|
||||
player_score = 0
|
||||
bot_score = 0
|
||||
while endTheGame.lower() != "y":
|
||||
ply = takePlayerInput()
|
||||
bt = getBotInput()
|
||||
print("Bot Entered -", bt)
|
||||
winner = checkWinner(player=ply, bot=bt)
|
||||
print("Winner is - ", winner)
|
||||
if winner == "Player":
|
||||
player_score += 2
|
||||
elif winner == "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 want to end Y/N - ")
|
||||
|
||||
|
||||
# In[8]:
|
||||
|
||||
|
||||
rockPaperScissor()
|
||||
|
||||
|
||||
# In[ ]:
|
Loading…
Reference in New Issue
Block a user