Skip to content

Instantly share code, notes, and snippets.

@duncanmorris
Created January 25, 2018 12:22
Show Gist options
  • Save duncanmorris/15bc50fdcf0c240d9c074992ac4e833f to your computer and use it in GitHub Desktop.
Save duncanmorris/15bc50fdcf0c240d9c074992ac4e833f to your computer and use it in GitHub Desktop.
import random
moves = ['rock', 'paper', 'scissors']
winners = {
'player': 0,
'computer': 0
}
def get_computer_choices():
# Really hard TODO Can we do better than a random choice
return random.choice(moves)
def get_winner(computer_choice, player_choice):
computer_choice = computer_choice.lower()
player_choice = player_choice.lower()
# TODO work out who actually won
winner = 'computer'
if winner == "computer":
msg = 'My {computer} beats your {player}. I win!'
else:
msg = 'My {computer} loses to your {player}. You win :('
print(msg.format(computer=computer_choice, player=player_choice))
return winner
def play():
# get the computers choice
computer_choice = get_computer_choices()
# get the winners choice
player_choice = input('Enter your choice: ')
# TODO - make sure they enter a valid choice
# work out the winner
winner = get_winner(computer_choice, player_choice)
# Add 1 to the winners list
winners[winner] += 1
print_scores()
again = input("Play again? y/n: ")
if again.lower() == 'y':
play()
def print_scores():
total = winners['player'] + winners['computer']
print("We've played {total} games. You've won {won}".format(
total=total,
won=winners['player']
))
# TODO - Make this more interesting.
# e.g. put well done if the player is winning overall.
# or put 'you need to be better than that to beat me' if the computer is
if __name__ == '__main__':
print("Let's play Rock, Paper, Scissors")
play()
print("Thanks for playing.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment