Skip to content

Instantly share code, notes, and snippets.

@dterracino
Forked from Echocage/Spock.py
Created February 27, 2020 21:57
Show Gist options
  • Save dterracino/b62f2598603adc96745e3a251436ea16 to your computer and use it in GitHub Desktop.
Save dterracino/b62f2598603adc96745e3a251436ea16 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