Skip to content

Instantly share code, notes, and snippets.

Created June 14, 2014 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c4ff49314b3c52e3c2c5 to your computer and use it in GitHub Desktop.
Save anonymous/c4ff49314b3c52e3c2c5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from random import randint
def player_choose():
print '''Choose a play:
1. Rock
2. Paper
3. Scissors
4. Lizard
5. Spock
6. Quit game'''
choose = '0'
while len(choose) != 1 or choose not in '123456':
choose = raw_input('Choose: ')
return choose
def compare_choices(computer, human, rule_book, score):
if computer == human:
return 'It\'s a tie. \n' + str(score) + '\n'
elif human in rule_book[computer]:
score['Computer'] += 1
return rule_book[computer][human] + ' Computer wins. \n' + str(score) + '\n'
else:
score['Player'] += 1
return rule_book[human][computer] + ' Player wins. \n' + str(score) + '\n'
def main():
score = {'Player' : 0, 'Computer' : 0}
the_rules = {'1' : {'3' : 'Rock crushes Scissors.', '4' : 'Rock crushes Lizard.'},
'2' : {'1' : 'Paper covers Rock.', '5' : 'Paper disproves Spock.'},
'3' : {'2' : 'Scissors cut Paper.', '4' : 'Scissors decapitate Lizard.'},
'4' : {'2' : 'Lizard eats Paper.', '5' : 'Lizard poisons Spock.'},
'5' : {'1' : 'Spock vaporizes Rock.', '3' : 'Spock smashes Scissors.'}}
the_options = {'1' : 'Rock.', '2' : 'Paper.', '3' : 'Scissors.', '4' : 'Lizard.', '5' : 'Spock.'}
player_choice = '0'
while player_choice != '6':
player_choice = player_choose()
if player_choice == '6':
print 'Goodbye.'
break
else:
computer_choice = str(randint(1,5))
print 'Player chooses ' + the_options[player_choice]
print 'Computer chooses ' + the_options[computer_choice]
print compare_choices(computer_choice, player_choice, the_rules, score)
player_choice = '0'
return 0
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment