Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created July 24, 2015 17:12
Show Gist options
  • Save Echocage/dc54c7dd3a00fc7dad9b to your computer and use it in GitHub Desktop.
Save Echocage/dc54c7dd3a00fc7dad9b to your computer and use it in GitHub Desktop.
import random
relationships = {'Spock': {'Scissors': 'smashes', 'Rock': 'vaporizes'},
'Scissors': {'Paper': 'cuts', 'Lizard': 'decapitates'},
'Lizard': {'Paper': 'eats', 'Spock': 'poisons'},
'Rock': {'Lizard': 'crushes', 'Scissors': 'crushes'},
'Paper': {'Spock': 'disapproves', 'Rock': 'covers'}
}
def get_match_results(player, player2):
if player == player2:
return 'Tie!'
if player2 in relationships[player]:
return ' '.join((player, relationships[player][player2], player2))
elif player in relationships[player2]:
return ' '.join((player2, relationships[player2][player], player))
def play_game():
for player_choice in relationships.keys():
computer_choice = random.choice(list(relationships.keys()))
print(get_match_results(player_choice, computer_choice))
if __name__ == '__main__':
play_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment