Update GAME-paper-scissors-stone

This commit is contained in:
tk20blue 2021-01-11 15:19:10 +00:00 committed by GitHub
parent dfba4d339e
commit cb2a1edd8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,13 @@
# You Vs. The Bot
import random
outcomes = ["Paper", "Scissors", "Stone"]
userscore = 0
botscore = 0
user_to_move = {"a": "Paper", "b": "Scissors", "c": "Stone"}
# Ask how many games
while True:
try:
games = int(input("How many games would you like to play? "))
@ -11,10 +15,7 @@ while True:
except:
print("That isn't a valid number")
user_to_move = {"a": "Paper", "b" : "Scissors", "c" : "Stone"}
valid_enteries = ("a", "b", "c")
# Play the game
while userscore < games and botscore < games:
while True:
try:
@ -29,33 +30,37 @@ while userscore < games and botscore < games:
bot_answer = random.choice(outcomes)
print("The bot answered: " + bot_answer)
def game_result(useranswer, bot_answer):
# Work out who won the game
def game_result(useranswer, botanswer):
if useranswer == bot_answer:
return "Draw"
elif useranswer == "Stone" and bot_answer == "Scissors":
elif useranswer == "Stone" and botanswer == "Scissors":
return "You Win!"
elif useranswer == "Paper" and bot_answer == "Stone":
elif useranswer == "Paper" and botanswer == "Stone":
return "You Win!"
elif useranswer == "Scissors" and bot_answer == "Paper":
elif useranswer == "Scissors" and botanswer == "Paper":
return "You Win!"
elif useranswer == "Stone" and bot_answer == "Paper":
elif useranswer == "Stone" and botanswer == "Paper":
return "You Lose!"
elif useranswer == "Paper" and bot_answer == "Scissors":
elif useranswer == "Paper" and botanswer == "Scissors":
return "You Lose!"
elif useranswer == "Scissors" and bot_answer == "Stone":
elif useranswer == "Scissors" and botanswer == "Stone":
return "You Lose!"
else: return "Error"
else:
return "Error"
if game_result(user_answer, bot_answer) == "You Win!":
userscore += 1
elif game_result(user_answer, bot_answer) == "You Lose!":
botscore += 1
else: pass
else:
pass
# Show user the results
print(game_result(user_answer, bot_answer))
print(f'Your score is {userscore} and the bot score is {botscore}')
# Final Scores
if userscore > botscore:
print("\nFINAL RESULT : YOU'RE A WINNER ! HURRAH !")
else: