Created
July 24, 2015 17:12
-
-
Save Echocage/dc54c7dd3a00fc7dad9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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