mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-01-31 05:33:41 +00:00
Update GAME-paper-scissors-stone
This commit is contained in:
parent
dfba4d339e
commit
cb2a1edd8f
|
@ -1,9 +1,13 @@
|
||||||
|
# You Vs. The Bot
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
outcomes = ["Paper", "Scissors", "Stone"]
|
outcomes = ["Paper", "Scissors", "Stone"]
|
||||||
userscore = 0
|
userscore = 0
|
||||||
botscore = 0
|
botscore = 0
|
||||||
|
user_to_move = {"a": "Paper", "b": "Scissors", "c": "Stone"}
|
||||||
|
|
||||||
|
# Ask how many games
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
games = int(input("How many games would you like to play? "))
|
games = int(input("How many games would you like to play? "))
|
||||||
|
@ -11,10 +15,7 @@ while True:
|
||||||
except:
|
except:
|
||||||
print("That isn't a valid number")
|
print("That isn't a valid number")
|
||||||
|
|
||||||
user_to_move = {"a": "Paper", "b" : "Scissors", "c" : "Stone"}
|
# Play the game
|
||||||
|
|
||||||
valid_enteries = ("a", "b", "c")
|
|
||||||
|
|
||||||
while userscore < games and botscore < games:
|
while userscore < games and botscore < games:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -29,33 +30,37 @@ while userscore < games and botscore < games:
|
||||||
bot_answer = random.choice(outcomes)
|
bot_answer = random.choice(outcomes)
|
||||||
print("The bot answered: " + bot_answer)
|
print("The bot answered: " + bot_answer)
|
||||||
|
|
||||||
|
# Work out who won the game
|
||||||
def game_result(useranswer, bot_answer):
|
def game_result(useranswer, botanswer):
|
||||||
if useranswer == bot_answer:
|
if useranswer == bot_answer:
|
||||||
return "Draw"
|
return "Draw"
|
||||||
elif useranswer == "Stone" and bot_answer == "Scissors":
|
elif useranswer == "Stone" and botanswer == "Scissors":
|
||||||
return "You Win!"
|
return "You Win!"
|
||||||
elif useranswer == "Paper" and bot_answer == "Stone":
|
elif useranswer == "Paper" and botanswer == "Stone":
|
||||||
return "You Win!"
|
return "You Win!"
|
||||||
elif useranswer == "Scissors" and bot_answer == "Paper":
|
elif useranswer == "Scissors" and botanswer == "Paper":
|
||||||
return "You Win!"
|
return "You Win!"
|
||||||
elif useranswer == "Stone" and bot_answer == "Paper":
|
elif useranswer == "Stone" and botanswer == "Paper":
|
||||||
return "You Lose!"
|
return "You Lose!"
|
||||||
elif useranswer == "Paper" and bot_answer == "Scissors":
|
elif useranswer == "Paper" and botanswer == "Scissors":
|
||||||
return "You Lose!"
|
return "You Lose!"
|
||||||
elif useranswer == "Scissors" and bot_answer == "Stone":
|
elif useranswer == "Scissors" and botanswer == "Stone":
|
||||||
return "You Lose!"
|
return "You Lose!"
|
||||||
else: return "Error"
|
else:
|
||||||
|
return "Error"
|
||||||
|
|
||||||
if game_result(user_answer, bot_answer) == "You Win!":
|
if game_result(user_answer, bot_answer) == "You Win!":
|
||||||
userscore += 1
|
userscore += 1
|
||||||
elif game_result(user_answer, bot_answer) == "You Lose!":
|
elif game_result(user_answer, bot_answer) == "You Lose!":
|
||||||
botscore += 1
|
botscore += 1
|
||||||
else: pass
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Show user the results
|
||||||
print(game_result(user_answer, bot_answer))
|
print(game_result(user_answer, bot_answer))
|
||||||
print(f'Your score is {userscore} and the bot score is {botscore}')
|
print(f'Your score is {userscore} and the bot score is {botscore}')
|
||||||
|
|
||||||
|
# Final Scores
|
||||||
if userscore > botscore:
|
if userscore > botscore:
|
||||||
print("\nFINAL RESULT : YOU'RE A WINNER ! HURRAH !")
|
print("\nFINAL RESULT : YOU'RE A WINNER ! HURRAH !")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user