Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- '''
- scissors cuts paper
- paper covers rock
- rock crushes lizard
- lizard poisons Spock
- Spock smashes scissors
- scissors decapitates lizard
- lizard eats paper
- paper disproves Spock
- Spock vaporizes rock
- rock crushes scissors
- '''
- from random import choice
- import readline
- RULES = list(map(str.split, __doc__.lower().strip().split('\n')))
- OPTIONS = ({winner for winner, verb, loser in RULES}
- | {loser for winner, verb, loser in RULES})
- PROMPT = "Please select: " + ', '.join(sorted(OPTIONS)) + '\n'
- ################################################################################
- def test(a, b, rules=RULES):
- a, b = a.lower(), b.lower()
- for rule in rules:
- winner, verb, loser = rule
- if (a, b) == (winner, loser): return a, ' '.join(rule)
- if (b, a) == (winner, loser): return b, ' '.join(rule)
- ################################################################################
- if __name__ == '__main__':
- print(__doc__)
- print()
- try:
- while True:
- user = None
- while user not in OPTIONS:
- user = input(PROMPT).lower()
- machine = choice(list(OPTIONS))
- try:
- winner, rule = test(user, machine)
- result = 'you win' if user == winner else 'you lose'
- print(user, 'v.', machine, '->', result, '\t(%s)' % rule)
- except: print('tie')
- print()
- except EOFError: pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement